@aigne/core 1.28.2 → 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 (44) hide show
  1. package/CHANGELOG.md +7 -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/dts/agents/agent.d.ts +1 -0
  18. package/lib/dts/agents/team-agent.d.ts +59 -2
  19. package/lib/dts/agents/transform-agent.d.ts +82 -0
  20. package/lib/dts/index.d.ts +1 -0
  21. package/lib/dts/loader/agent-js.d.ts +2 -2
  22. package/lib/dts/loader/agent-yaml.d.ts +35 -44
  23. package/lib/dts/loader/schema.d.ts +2 -1
  24. package/lib/esm/agents/agent.d.ts +1 -0
  25. package/lib/esm/agents/agent.js +8 -5
  26. package/lib/esm/agents/team-agent.d.ts +59 -2
  27. package/lib/esm/agents/team-agent.js +53 -2
  28. package/lib/esm/agents/transform-agent.d.ts +82 -0
  29. package/lib/esm/agents/transform-agent.js +60 -0
  30. package/lib/esm/index.d.ts +1 -0
  31. package/lib/esm/index.js +1 -0
  32. package/lib/esm/loader/agent-js.d.ts +2 -2
  33. package/lib/esm/loader/agent-js.js +9 -16
  34. package/lib/esm/loader/agent-yaml.d.ts +35 -44
  35. package/lib/esm/loader/agent-yaml.js +56 -104
  36. package/lib/esm/loader/index.js +28 -11
  37. package/lib/esm/loader/schema.d.ts +2 -1
  38. package/lib/esm/loader/schema.js +3 -0
  39. package/package.json +2 -1
  40. package/lib/cjs/utils/camelize.d.ts +0 -13
  41. package/lib/cjs/utils/camelize.js +0 -16
  42. package/lib/dts/utils/camelize.d.ts +0 -13
  43. package/lib/esm/utils/camelize.d.ts +0 -13
  44. package/lib/esm/utils/camelize.js +0 -10
@@ -1,123 +1,78 @@
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.loadAgentFromYamlFile = loadAgentFromYamlFile;
4
7
  const json_schema_to_zod_1 = require("@aigne/json-schema-to-zod");
5
8
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
9
+ const camelize_ts_1 = __importDefault(require("camelize-ts"));
6
10
  const yaml_1 = require("yaml");
7
11
  const zod_1 = require("zod");
8
12
  const ai_agent_js_1 = require("../agents/ai-agent.js");
9
13
  const team_agent_js_1 = require("../agents/team-agent.js");
10
- const camelize_js_1 = require("../utils/camelize.js");
11
14
  const type_utils_js_1 = require("../utils/type-utils.js");
12
15
  const schema_js_1 = require("./schema.js");
13
- const agentFileSchema = zod_1.z.discriminatedUnion("type", [
14
- zod_1.z.object({
15
- type: zod_1.z.literal("ai"),
16
- name: zod_1.z.string(),
17
- description: zod_1.z
18
- .string()
19
- .nullish()
20
- .transform((v) => v ?? undefined),
21
- instructions: zod_1.z
22
- .union([
23
- zod_1.z.string(),
24
- zod_1.z.object({
25
- url: zod_1.z.string(),
26
- }),
27
- ])
28
- .nullish()
29
- .transform((v) => v ?? undefined),
30
- input_key: zod_1.z
31
- .string()
32
- .nullish()
33
- .transform((v) => v ?? undefined),
34
- input_schema: schema_js_1.inputOutputSchema
35
- .nullish()
36
- .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
37
- output_schema: schema_js_1.inputOutputSchema
38
- .nullish()
39
- .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
40
- output_key: zod_1.z
41
- .string()
42
- .nullish()
43
- .transform((v) => v ?? undefined),
44
- skills: zod_1.z
45
- .array(zod_1.z.string())
46
- .nullish()
47
- .transform((v) => v ?? undefined),
48
- tool_choice: zod_1.z
49
- .nativeEnum(ai_agent_js_1.AIAgentToolChoice)
50
- .nullish()
51
- .transform((v) => v ?? undefined),
52
- memory: zod_1.z
53
- .union([
54
- zod_1.z.boolean(),
16
+ async function loadAgentFromYamlFile(path) {
17
+ const agentSchema = zod_1.z.lazy(() => {
18
+ const baseAgentSchema = zod_1.z.object({
19
+ name: (0, schema_js_1.optionalize)(zod_1.z.string()),
20
+ description: (0, schema_js_1.optionalize)(zod_1.z.string()),
21
+ inputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
22
+ outputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
23
+ skills: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.union([zod_1.z.string(), agentSchema]))),
24
+ memory: (0, schema_js_1.optionalize)(zod_1.z.union([
25
+ zod_1.z.boolean(),
26
+ zod_1.z.object({
27
+ provider: zod_1.z.string(),
28
+ subscribeTopic: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
29
+ }),
30
+ ])),
31
+ });
32
+ return zod_1.z.discriminatedUnion("type", [
33
+ zod_1.z
34
+ .object({
35
+ type: zod_1.z.literal("ai"),
36
+ instructions: (0, schema_js_1.optionalize)(zod_1.z.union([
37
+ zod_1.z.string(),
38
+ zod_1.z.object({
39
+ url: zod_1.z.string(),
40
+ }),
41
+ ])).transform((v) => typeof v === "string"
42
+ ? v
43
+ : v && index_js_1.nodejs.fs.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), v.url), "utf8")),
44
+ inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
45
+ outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
46
+ toolChoice: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(ai_agent_js_1.AIAgentToolChoice)),
47
+ })
48
+ .extend(baseAgentSchema.shape),
55
49
  zod_1.z.object({
56
- provider: zod_1.z.string(),
57
- subscribe_topic: zod_1.z
58
- .array(zod_1.z.string())
59
- .nullish()
60
- .transform((v) => v ?? undefined),
50
+ type: zod_1.z.literal("mcp"),
51
+ url: (0, schema_js_1.optionalize)(zod_1.z.string()),
52
+ command: (0, schema_js_1.optionalize)(zod_1.z.string()),
53
+ args: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
61
54
  }),
62
- ])
63
- .nullish()
64
- .transform((v) => v || undefined),
65
- }),
66
- zod_1.z.object({
67
- type: zod_1.z.literal("mcp"),
68
- url: zod_1.z
69
- .string()
70
- .nullish()
71
- .transform((v) => v ?? undefined),
72
- command: zod_1.z
73
- .string()
74
- .nullish()
75
- .transform((v) => v ?? undefined),
76
- args: zod_1.z
77
- .array(zod_1.z.string())
78
- .nullish()
79
- .transform((v) => v ?? undefined),
80
- }),
81
- zod_1.z.object({
82
- type: zod_1.z.literal("team"),
83
- name: zod_1.z.string(),
84
- description: zod_1.z
85
- .string()
86
- .nullish()
87
- .transform((v) => v ?? undefined),
88
- input_schema: schema_js_1.inputOutputSchema
89
- .nullish()
90
- .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
91
- output_schema: schema_js_1.inputOutputSchema
92
- .nullish()
93
- .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
94
- skills: zod_1.z
95
- .array(zod_1.z.string())
96
- .nullish()
97
- .transform((v) => v ?? undefined),
98
- mode: zod_1.z
99
- .nativeEnum(team_agent_js_1.ProcessMode)
100
- .nullish()
101
- .transform((v) => v ?? undefined),
102
- }),
103
- ]);
104
- async function loadAgentFromYamlFile(path) {
55
+ zod_1.z
56
+ .object({
57
+ type: zod_1.z.literal("team"),
58
+ mode: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(team_agent_js_1.ProcessMode)),
59
+ iterateOn: (0, schema_js_1.optionalize)(zod_1.z.string()),
60
+ })
61
+ .extend(baseAgentSchema.shape),
62
+ zod_1.z
63
+ .object({
64
+ type: zod_1.z.literal("transform"),
65
+ jsonata: zod_1.z.string(),
66
+ })
67
+ .extend(baseAgentSchema.shape),
68
+ ]);
69
+ });
105
70
  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}`));
106
71
  const json = await (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
107
- const agent = await (0, type_utils_js_1.tryOrThrow)(async () => (0, camelize_js_1.customCamelize)(await agentFileSchema.parseAsync({
72
+ const agent = await (0, type_utils_js_1.tryOrThrow)(async () => await agentSchema.parseAsync((0, camelize_ts_1.default)({
108
73
  ...json,
109
74
  type: json.type ?? "ai",
110
75
  skills: json.skills ?? json.tools,
111
- }), {
112
- shallowKeys: ["input_schema", "output_schema"],
113
- }), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
114
- if (agent.type === "ai") {
115
- return {
116
- ...agent,
117
- instructions: typeof agent.instructions === "object" && "url" in agent.instructions
118
- ? await index_js_1.nodejs.fs.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), agent.instructions.url), "utf8")
119
- : agent.instructions,
120
- };
121
- }
76
+ })), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
122
77
  return agent;
123
78
  }
@@ -11,6 +11,7 @@ const agent_js_1 = require("../agents/agent.js");
11
11
  const ai_agent_js_1 = require("../agents/ai-agent.js");
12
12
  const mcp_agent_js_1 = require("../agents/mcp-agent.js");
13
13
  const team_agent_js_1 = require("../agents/team-agent.js");
14
+ const transform_agent_js_1 = require("../agents/transform-agent.js");
14
15
  const type_utils_js_1 = require("../utils/type-utils.js");
15
16
  const agent_js_js_1 = require("./agent-js.js");
16
17
  const agent_yaml_js_1 = require("./agent-yaml.js");
@@ -42,20 +43,29 @@ async function loadAgent(path, options) {
42
43
  }
43
44
  if ([".yml", ".yaml"].includes(index_js_1.nodejs.path.extname(path))) {
44
45
  const agent = await (0, agent_yaml_js_1.loadAgentFromYamlFile)(path);
45
- const skills = "skills" in agent
46
- ? agent.skills &&
47
- (await Promise.all(agent.skills.map((filename) => loadAgent(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), filename), options))))
48
- : undefined;
49
- if (agent.type === "ai") {
46
+ return parseAgent(path, agent, options);
47
+ }
48
+ throw new Error(`Unsupported agent file type: ${path}`);
49
+ }
50
+ async function parseAgent(path, agent, options) {
51
+ const skills = "skills" in agent
52
+ ? agent.skills &&
53
+ (await Promise.all(agent.skills.map((skill) => typeof skill === "string"
54
+ ? loadAgent(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), skill), options)
55
+ : parseAgent(path, skill, options))))
56
+ : undefined;
57
+ const memory = "memory" in agent && options?.memories?.length
58
+ ? await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {})
59
+ : undefined;
60
+ switch (agent.type) {
61
+ case "ai": {
50
62
  return ai_agent_js_1.AIAgent.from({
51
63
  ...agent,
52
- memory: !options?.memories?.length || !agent.memory
53
- ? undefined
54
- : await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {}),
64
+ memory,
55
65
  skills,
56
66
  });
57
67
  }
58
- if (agent.type === "mcp") {
68
+ case "mcp": {
59
69
  if (agent.url) {
60
70
  return mcp_agent_js_1.MCPAgent.from({
61
71
  url: agent.url,
@@ -69,14 +79,21 @@ async function loadAgent(path, options) {
69
79
  }
70
80
  throw new Error(`Missing url or command in mcp agent: ${path}`);
71
81
  }
72
- if (agent.type === "team") {
82
+ case "team": {
73
83
  return team_agent_js_1.TeamAgent.from({
74
84
  ...agent,
85
+ memory,
86
+ skills,
87
+ });
88
+ }
89
+ case "transform": {
90
+ return transform_agent_js_1.TransformAgent.from({
91
+ ...agent,
92
+ memory,
75
93
  skills,
76
94
  });
77
95
  }
78
96
  }
79
- throw new Error(`Unsupported agent file type: ${path}`);
80
97
  }
81
98
  async function loadMemory(memories, provider, options) {
82
99
  const M = !provider
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { type ZodType, z } from "zod";
2
2
  export declare const inputOutputSchema: z.ZodObject<{
3
3
  type: z.ZodLiteral<"object">;
4
4
  properties: z.ZodRecord<z.ZodString, z.ZodAny>;
@@ -15,3 +15,4 @@ export declare const inputOutputSchema: z.ZodObject<{
15
15
  required?: string[] | undefined;
16
16
  additionalProperties?: boolean | undefined;
17
17
  }>;
18
+ export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inputOutputSchema = void 0;
4
+ exports.optionalize = optionalize;
4
5
  const zod_1 = require("zod");
5
6
  exports.inputOutputSchema = zod_1.z.object({
6
7
  type: zod_1.z.literal("object"),
@@ -8,3 +9,6 @@ exports.inputOutputSchema = zod_1.z.object({
8
9
  required: zod_1.z.array(zod_1.z.string()).optional(),
9
10
  additionalProperties: zod_1.z.boolean().optional(),
10
11
  });
12
+ function optionalize(schema) {
13
+ return schema.nullish().transform((v) => v ?? undefined);
14
+ }
@@ -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
  *
@@ -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
  }
@@ -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
+ }
@@ -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";
@@ -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, {
@@ -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 {};
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { type ZodType, z } from "zod";
2
2
  export declare const inputOutputSchema: z.ZodObject<{
3
3
  type: z.ZodLiteral<"object">;
4
4
  properties: z.ZodRecord<z.ZodString, z.ZodAny>;
@@ -15,3 +15,4 @@ export declare const inputOutputSchema: z.ZodObject<{
15
15
  required?: string[] | undefined;
16
16
  additionalProperties?: boolean | undefined;
17
17
  }>;
18
+ export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
@@ -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
  *
@@ -326,11 +326,7 @@ export class Agent {
326
326
  },
327
327
  }), opts);
328
328
  }
329
- return await this.checkResponseByGuideRails(input, this.processAgentOutput(parsedInput, response instanceof ReadableStream
330
- ? await agentResponseStreamToObject(response)
331
- : isAsyncGenerator(response)
332
- ? await agentResponseStreamToObject(response)
333
- : response, opts), opts);
329
+ return await this.checkResponseByGuideRails(input, this.processAgentOutput(parsedInput, await agentProcessResultToObject(response), opts), opts);
334
330
  }
335
331
  catch (error) {
336
332
  throw await this.processAgentError(input, error, opts);
@@ -578,6 +574,13 @@ export function textDelta(textDelta) {
578
574
  export function jsonDelta(jsonDelta) {
579
575
  return { delta: { json: jsonDelta } };
580
576
  }
577
+ export async function agentProcessResultToObject(response) {
578
+ return response instanceof ReadableStream
579
+ ? await agentResponseStreamToObject(response)
580
+ : isAsyncGenerator(response)
581
+ ? await agentResponseStreamToObject(response)
582
+ : response;
583
+ }
581
584
  function checkAgentInputOutputSchema(schema) {
582
585
  if (!(schema instanceof ZodObject) && typeof schema !== "function") {
583
586
  throw new Error(`schema must be a zod object or function return a zod object, got: ${typeof schema}`);