@aigne/core 1.51.0 → 1.53.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 (60) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/cjs/agents/agent.d.ts +2 -0
  3. package/lib/cjs/agents/agent.js +8 -1
  4. package/lib/cjs/agents/chat-model.d.ts +17 -3
  5. package/lib/cjs/agents/chat-model.js +8 -4
  6. package/lib/cjs/agents/image-agent.d.ts +21 -0
  7. package/lib/cjs/agents/image-agent.js +43 -0
  8. package/lib/cjs/agents/image-model.d.ts +115 -0
  9. package/lib/cjs/agents/image-model.js +60 -0
  10. package/lib/cjs/aigne/aigne.d.ts +10 -1
  11. package/lib/cjs/aigne/aigne.js +10 -6
  12. package/lib/cjs/aigne/context.d.ts +5 -1
  13. package/lib/cjs/aigne/context.js +6 -0
  14. package/lib/cjs/index.d.ts +2 -0
  15. package/lib/cjs/index.js +2 -0
  16. package/lib/cjs/loader/agent-yaml.d.ts +6 -1
  17. package/lib/cjs/loader/agent-yaml.js +18 -9
  18. package/lib/cjs/loader/index.d.ts +46 -44
  19. package/lib/cjs/loader/index.js +35 -12
  20. package/lib/cjs/prompt/prompt-builder.d.ts +3 -0
  21. package/lib/cjs/prompt/prompt-builder.js +8 -0
  22. package/lib/cjs/utils/camelize.d.ts +7 -1
  23. package/lib/cjs/utils/camelize.js +30 -13
  24. package/lib/cjs/utils/type-utils.d.ts +1 -1
  25. package/lib/dts/agents/agent.d.ts +2 -0
  26. package/lib/dts/agents/chat-model.d.ts +17 -3
  27. package/lib/dts/agents/image-agent.d.ts +21 -0
  28. package/lib/dts/agents/image-model.d.ts +115 -0
  29. package/lib/dts/aigne/aigne.d.ts +10 -1
  30. package/lib/dts/aigne/context.d.ts +5 -1
  31. package/lib/dts/index.d.ts +2 -0
  32. package/lib/dts/loader/agent-yaml.d.ts +6 -1
  33. package/lib/dts/loader/index.d.ts +46 -44
  34. package/lib/dts/prompt/prompt-builder.d.ts +3 -0
  35. package/lib/dts/utils/camelize.d.ts +7 -1
  36. package/lib/dts/utils/type-utils.d.ts +1 -1
  37. package/lib/esm/agents/agent.d.ts +2 -0
  38. package/lib/esm/agents/agent.js +8 -1
  39. package/lib/esm/agents/chat-model.d.ts +17 -3
  40. package/lib/esm/agents/chat-model.js +7 -3
  41. package/lib/esm/agents/image-agent.d.ts +21 -0
  42. package/lib/esm/agents/image-agent.js +36 -0
  43. package/lib/esm/agents/image-model.d.ts +115 -0
  44. package/lib/esm/agents/image-model.js +56 -0
  45. package/lib/esm/aigne/aigne.d.ts +10 -1
  46. package/lib/esm/aigne/aigne.js +10 -6
  47. package/lib/esm/aigne/context.d.ts +5 -1
  48. package/lib/esm/aigne/context.js +6 -0
  49. package/lib/esm/index.d.ts +2 -0
  50. package/lib/esm/index.js +2 -0
  51. package/lib/esm/loader/agent-yaml.d.ts +6 -1
  52. package/lib/esm/loader/agent-yaml.js +18 -9
  53. package/lib/esm/loader/index.d.ts +46 -44
  54. package/lib/esm/loader/index.js +36 -13
  55. package/lib/esm/prompt/prompt-builder.d.ts +3 -0
  56. package/lib/esm/prompt/prompt-builder.js +8 -0
  57. package/lib/esm/utils/camelize.d.ts +7 -1
  58. package/lib/esm/utils/camelize.js +29 -13
  59. package/lib/esm/utils/type-utils.d.ts +1 -1
  60. package/package.json +3 -3
@@ -1,51 +1,55 @@
1
- import type { Camelize } from "camelize-ts";
2
1
  import { z } from "zod";
3
2
  import { Agent, type AgentOptions } from "../agents/agent.js";
4
3
  import type { ChatModel } from "../agents/chat-model.js";
4
+ import type { ImageModel } from "../agents/image-model.js";
5
5
  import type { AIGNEOptions } from "../aigne/aigne.js";
6
6
  import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
7
7
  import { type PromiseOrValue } from "../utils/type-utils.js";
8
8
  export interface LoadOptions {
9
- loadModel: (model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>) => PromiseOrValue<ChatModel | undefined>;
10
9
  memories?: {
11
10
  new (parameters?: MemoryAgentOptions): MemoryAgent;
12
11
  }[];
13
- path: string;
14
- model?: ChatModel;
12
+ model?: ChatModel | ((model?: z.infer<typeof aigneFileSchema>["chatModel"]) => PromiseOrValue<ChatModel | undefined>);
13
+ imageModel?: ImageModel | ((model?: z.infer<typeof aigneFileSchema>["imageModel"]) => PromiseOrValue<ImageModel | undefined>);
15
14
  }
16
- export declare function load(options: LoadOptions): Promise<AIGNEOptions>;
15
+ export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
17
16
  export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
18
17
  declare const aigneFileSchema: z.ZodObject<{
19
18
  name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
20
19
  description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
21
- model: z.ZodEffects<z.ZodType<string | {
22
- name?: string | null | undefined;
23
- temperature?: number | null | undefined;
24
- topP?: number | null | undefined;
25
- frequencyPenalty?: number | null | undefined;
26
- presencePenalty?: number | null | undefined;
27
- provider?: string | null | undefined;
20
+ chatModel: z.ZodEffects<z.ZodEffects<z.ZodType<string | {
21
+ model?: string | undefined;
22
+ temperature?: number | undefined;
23
+ topP?: number | undefined;
24
+ frequencyPenalty?: number | undefined;
25
+ presencePenalty?: number | undefined;
28
26
  } | undefined, z.ZodTypeDef, string | {
29
- name?: string | null | undefined;
30
- temperature?: number | null | undefined;
31
- topP?: number | null | undefined;
32
- frequencyPenalty?: number | null | undefined;
33
- presencePenalty?: number | null | undefined;
34
- provider?: string | null | undefined;
27
+ model?: string | undefined;
28
+ temperature?: number | undefined;
29
+ topP?: number | undefined;
30
+ frequencyPenalty?: number | undefined;
31
+ presencePenalty?: number | undefined;
32
+ } | undefined>, string | {
33
+ model?: string | undefined;
34
+ temperature?: number | undefined;
35
+ topP?: number | undefined;
36
+ frequencyPenalty?: number | undefined;
37
+ presencePenalty?: number | undefined;
38
+ } | undefined, unknown>, {
39
+ model?: string | undefined;
40
+ temperature?: number | undefined;
41
+ topP?: number | undefined;
42
+ frequencyPenalty?: number | undefined;
43
+ presencePenalty?: number | undefined;
44
+ } | undefined, unknown>;
45
+ imageModel: z.ZodEffects<z.ZodType<string | {
46
+ model?: string | undefined;
47
+ } | undefined, z.ZodTypeDef, string | {
48
+ model?: string | undefined;
35
49
  } | undefined>, {
36
- name?: string | null | undefined;
37
- temperature?: number | null | undefined;
38
- topP?: number | null | undefined;
39
- frequencyPenalty?: number | null | undefined;
40
- presencePenalty?: number | null | undefined;
41
- provider?: string | null | undefined;
50
+ model?: string | undefined;
42
51
  } | undefined, string | {
43
- name?: string | null | undefined;
44
- temperature?: number | null | undefined;
45
- topP?: number | null | undefined;
46
- frequencyPenalty?: number | null | undefined;
47
- presencePenalty?: number | null | undefined;
48
- provider?: string | null | undefined;
52
+ model?: string | undefined;
49
53
  } | undefined>;
50
54
  agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
51
55
  skills: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
@@ -63,15 +67,17 @@ declare const aigneFileSchema: z.ZodObject<{
63
67
  name?: string | undefined;
64
68
  description?: string | undefined;
65
69
  skills?: string[] | undefined;
66
- model?: {
67
- name?: string | null | undefined;
68
- temperature?: number | null | undefined;
69
- topP?: number | null | undefined;
70
- frequencyPenalty?: number | null | undefined;
71
- presencePenalty?: number | null | undefined;
72
- provider?: string | null | undefined;
70
+ imageModel?: {
71
+ model?: string | undefined;
73
72
  } | undefined;
74
73
  agents?: string[] | undefined;
74
+ chatModel?: {
75
+ model?: string | undefined;
76
+ temperature?: number | undefined;
77
+ topP?: number | undefined;
78
+ frequencyPenalty?: number | undefined;
79
+ presencePenalty?: number | undefined;
80
+ } | undefined;
75
81
  mcpServer?: {
76
82
  agents?: string[] | undefined;
77
83
  } | undefined;
@@ -82,15 +88,11 @@ declare const aigneFileSchema: z.ZodObject<{
82
88
  name?: string | undefined;
83
89
  description?: string | undefined;
84
90
  skills?: string[] | undefined;
85
- model?: string | {
86
- name?: string | null | undefined;
87
- temperature?: number | null | undefined;
88
- topP?: number | null | undefined;
89
- frequencyPenalty?: number | null | undefined;
90
- presencePenalty?: number | null | undefined;
91
- provider?: string | null | undefined;
91
+ imageModel?: string | {
92
+ model?: string | undefined;
92
93
  } | undefined;
93
94
  agents?: string[] | undefined;
95
+ chatModel?: unknown;
94
96
  mcpServer?: {
95
97
  agents?: string[] | undefined;
96
98
  } | undefined;
@@ -8,6 +8,7 @@ const yaml_1 = require("yaml");
8
8
  const zod_1 = require("zod");
9
9
  const agent_js_1 = require("../agents/agent.js");
10
10
  const ai_agent_js_1 = require("../agents/ai-agent.js");
11
+ const image_agent_js_1 = require("../agents/image-agent.js");
11
12
  const mcp_agent_js_1 = require("../agents/mcp-agent.js");
12
13
  const team_agent_js_1 = require("../agents/team-agent.js");
13
14
  const transform_agent_js_1 = require("../agents/transform-agent.js");
@@ -17,15 +18,18 @@ const agent_js_js_1 = require("./agent-js.js");
17
18
  const agent_yaml_js_1 = require("./agent-yaml.js");
18
19
  const schema_js_1 = require("./schema.js");
19
20
  const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
20
- async function load(options) {
21
- const { aigne, rootDir } = await loadAIGNEFile(options.path);
21
+ async function load(path, options = {}) {
22
+ const { aigne, rootDir } = await loadAIGNEFile(path);
22
23
  const allAgentPaths = new Set((0, type_utils_js_1.flat)(aigne.agents, aigne.skills, aigne.mcpServer?.agents, aigne.cli?.agents).map((i) => index_js_1.nodejs.path.join(rootDir, i)));
23
24
  const allAgents = Object.fromEntries(await Promise.all(Array.from(allAgentPaths).map(async (path) => [path, await loadAgent(path, options)])));
24
25
  const pickAgents = (paths) => paths.map((filename) => allAgents[index_js_1.nodejs.path.join(rootDir, filename)]).filter(type_utils_js_1.isNonNullable);
25
26
  return {
26
27
  ...aigne,
27
28
  rootDir,
28
- model: options?.model || (await options.loadModel(aigne.model)),
29
+ model: typeof options.model === "function" ? await options.model(aigne.chatModel) : options.model,
30
+ imageModel: typeof options.imageModel === "function"
31
+ ? await options.imageModel(aigne.imageModel)
32
+ : options.imageModel,
29
33
  agents: pickAgents(aigne.agents ?? []),
30
34
  skills: pickAgents(aigne.skills ?? []),
31
35
  mcpServer: {
@@ -104,6 +108,14 @@ async function parseAgent(path, agent, options, agentOptions) {
104
108
  prompt_builder_js_1.PromptBuilder.from(agent.instructions, { workingDir: index_js_1.nodejs.path.dirname(path) }),
105
109
  });
106
110
  }
111
+ case "image": {
112
+ return image_agent_js_1.ImageAgent.from({
113
+ ...baseOptions,
114
+ instructions: prompt_builder_js_1.PromptBuilder.from(agent.instructions, {
115
+ workingDir: index_js_1.nodejs.path.dirname(path),
116
+ }),
117
+ });
118
+ }
107
119
  case "mcp": {
108
120
  if (agent.url) {
109
121
  return mcp_agent_js_1.MCPAgent.from({
@@ -156,17 +168,28 @@ async function loadMemory(memories, provider, options) {
156
168
  const aigneFileSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
157
169
  name: (0, schema_js_1.optionalize)(zod_1.z.string()),
158
170
  description: (0, schema_js_1.optionalize)(zod_1.z.string()),
159
- model: (0, schema_js_1.optionalize)(zod_1.z.union([
171
+ chatModel: zod_1.z
172
+ .preprocess((v) => {
173
+ if (!(0, type_utils_js_1.isRecord)(v))
174
+ return v;
175
+ return { ...v, model: v.model || `${v.provider || ""}:${v.name || ""}` };
176
+ }, (0, schema_js_1.optionalize)(zod_1.z.union([
177
+ zod_1.z.string(),
178
+ (0, schema_js_1.camelizeSchema)(zod_1.z.object({
179
+ model: (0, schema_js_1.optionalize)(zod_1.z.string()),
180
+ temperature: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(2)),
181
+ topP: (0, schema_js_1.optionalize)(zod_1.z.number().min(0)),
182
+ frequencyPenalty: (0, schema_js_1.optionalize)(zod_1.z.number().min(-2).max(2)),
183
+ presencePenalty: (0, schema_js_1.optionalize)(zod_1.z.number().min(-2).max(2)),
184
+ })),
185
+ ])))
186
+ .transform((v) => (typeof v === "string" ? { model: v } : v)),
187
+ imageModel: (0, schema_js_1.optionalize)(zod_1.z.union([
160
188
  zod_1.z.string(),
161
189
  (0, schema_js_1.camelizeSchema)(zod_1.z.object({
162
- provider: zod_1.z.string().nullish(),
163
- name: zod_1.z.string().nullish(),
164
- temperature: zod_1.z.number().min(0).max(2).nullish(),
165
- topP: zod_1.z.number().min(0).nullish(),
166
- frequencyPenalty: zod_1.z.number().min(-2).max(2).nullish(),
167
- presencePenalty: zod_1.z.number().min(-2).max(2).nullish(),
190
+ model: (0, schema_js_1.optionalize)(zod_1.z.string()),
168
191
  })),
169
- ])).transform((v) => (typeof v === "string" ? { name: v } : v)),
192
+ ])).transform((v) => (typeof v === "string" ? { model: v } : v)),
170
193
  agents: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
171
194
  skills: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
172
195
  mcpServer: (0, schema_js_1.optionalize)(zod_1.z.object({
@@ -180,7 +203,7 @@ async function loadAIGNEFile(path) {
180
203
  const file = await findAIGNEFile(path);
181
204
  const raw = await (0, type_utils_js_1.tryOrThrow)(() => index_js_1.nodejs.fs.readFile(file, "utf8"), (error) => new Error(`Failed to load aigne.yaml from ${file}: ${error.message}`));
182
205
  const json = (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse aigne.yaml from ${file}: ${error.message}`));
183
- const aigne = (0, type_utils_js_1.tryOrThrow)(() => aigneFileSchema.parse({ ...json, model: json.model ?? json.chat_model ?? json.chatModel }), (error) => new Error(`Failed to validate aigne.yaml from ${file}: ${error.message}`));
206
+ const aigne = (0, type_utils_js_1.tryOrThrow)(() => aigneFileSchema.parse(json), (error) => new Error(`Failed to validate aigne.yaml from ${file}: ${error.message}`));
184
207
  return { aigne, rootDir: index_js_1.nodejs.path.dirname(file) };
185
208
  }
186
209
  async function findAIGNEFile(path) {
@@ -27,6 +27,9 @@ export declare class PromptBuilder {
27
27
  build(options: PromptBuildOptions): Promise<ChatModelInput & {
28
28
  toolAgents?: Agent[];
29
29
  }>;
30
+ buildImagePrompt(options: Pick<PromptBuildOptions, "input">): Promise<{
31
+ prompt: string;
32
+ }>;
30
33
  private buildMessages;
31
34
  private convertMemoriesToMessages;
32
35
  private buildResponseFormat;
@@ -68,6 +68,14 @@ class PromptBuilder {
68
68
  ...this.buildTools(options),
69
69
  };
70
70
  }
71
+ async buildImagePrompt(options) {
72
+ const messages = (await (typeof this.instructions === "string"
73
+ ? template_js_1.ChatMessagesTemplate.from([template_js_1.SystemMessageTemplate.from(this.instructions)])
74
+ : this.instructions)?.format(options.input, { workingDir: this.workingDir })) ?? [];
75
+ return {
76
+ prompt: messages.map((i) => i.content).join("\n"),
77
+ };
78
+ }
71
79
  async buildMessages(options) {
72
80
  const { input } = options;
73
81
  const inputKey = options.agent?.inputKey;
@@ -1 +1,7 @@
1
- export declare function camelize<T>(obj: T, shallow?: boolean): any;
1
+ export type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${P1}${Uppercase<P2>}${CamelCase<P3>}` : S;
2
+ export type CamelizeObject<T, S = false> = {
3
+ [K in keyof T as Uncapitalize<CamelCase<string & K>>]: T[K] extends Date ? T[K] : T[K] extends RegExp ? T[K] : T[K] extends Array<infer U> ? U extends object | undefined ? Array<CamelizeObject<U>> : T[K] : T[K] extends object | undefined ? S extends true ? T[K] : CamelizeObject<T[K]> : T[K];
4
+ };
5
+ export type Camelize<T, S = false> = T extends Array<infer U> ? Array<CamelizeObject<U, S>> : CamelizeObject<T, S>;
6
+ export declare function camelize<T, S extends boolean = false>(obj: T, shallow?: S): T extends string ? string : Camelize<T, S>;
7
+ export declare function snakelize<T, S extends boolean = false>(obj: T, shallow?: S): T extends string ? string : any;
@@ -1,21 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.camelize = camelize;
4
- const type_utils_js_1 = require("./type-utils.js");
5
- function camelize(obj, shallow = false) {
6
- if (Array.isArray(obj)) {
7
- return shallow ? obj : obj.map((item) => camelize(item, false));
8
- }
9
- if ((0, type_utils_js_1.isRecord)(obj)) {
10
- return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
11
- camelCase(key),
12
- shallow ? value : camelize(value, false),
13
- ]));
14
- }
15
- return obj;
4
+ exports.snakelize = snakelize;
5
+ function camelize(obj, shallow) {
6
+ return typeof obj === "string" ? camelCase(obj) : walk(obj, shallow, camelCase);
7
+ }
8
+ function snakelize(obj, shallow) {
9
+ return typeof obj === "string" ? snakeCase(obj) : walk(obj, shallow, snakeCase);
16
10
  }
17
11
  function camelCase(key) {
18
- key = key.replace(/[-_#@$\s]+(.)?/g, (_, char) => char.toUpperCase());
12
+ key = key.replace(/[_.-](\w|$)/g, (_, char) => char.toUpperCase());
19
13
  key = key.charAt(0).toLowerCase() + key.slice(1);
20
14
  return key;
21
15
  }
16
+ function snakeCase(key) {
17
+ return key.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
18
+ }
19
+ function walk(obj, shallow = false, transform) {
20
+ if (!obj || typeof obj !== "object")
21
+ return obj;
22
+ if (obj instanceof Date || obj instanceof RegExp)
23
+ return obj;
24
+ if (Array.isArray(obj))
25
+ return obj.map((v) => {
26
+ if (!shallow) {
27
+ return walk(v, shallow, transform);
28
+ }
29
+ if (typeof v === "object")
30
+ return walk(v, shallow, transform);
31
+ return v;
32
+ });
33
+ return Object.keys(obj).reduce((res, key) => {
34
+ const newKey = transform(key);
35
+ res[newKey] = shallow ? obj[key] : walk(obj[key], shallow, transform);
36
+ return res;
37
+ }, {});
38
+ }
@@ -18,7 +18,7 @@ export declare function unique<T>(arr: T[], key?: (item: T) => unknown): T[];
18
18
  export declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Pick<T, K>;
19
19
  export declare function omit<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
20
20
  export declare function omitDeep<T, K>(obj: T, ...keys: (K | K[])[]): unknown;
21
- export declare function omitBy<T extends Record<string, unknown>, K extends keyof T>(obj: T, predicate: (value: T[K], key: K) => boolean): Partial<T>;
21
+ export declare function omitBy<T extends object, K extends keyof T>(obj: T, predicate: (value: T[K], key: K) => boolean): Partial<T>;
22
22
  export declare function flat<T>(...value: (T | T[])[]): NonNullable<T>[];
23
23
  export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
24
24
  [key: string]: T;
@@ -116,6 +116,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
116
116
  * One or more memory agents this agent can use
117
117
  */
118
118
  memory?: MemoryAgent | MemoryAgent[];
119
+ asyncMemoryRecord?: boolean;
119
120
  /**
120
121
  * Maximum number of memory items to retrieve
121
122
  */
@@ -199,6 +200,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
199
200
  * List of memories this agent can use
200
201
  */
201
202
  readonly memories: MemoryAgent[];
203
+ asyncMemoryRecord?: boolean;
202
204
  tag?: string;
203
205
  /**
204
206
  * Maximum number of memory items to retrieve
@@ -1,5 +1,6 @@
1
+ import { z } from "zod";
1
2
  import type { PromiseOrValue } from "../utils/type-utils.js";
2
- import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message } from "./agent.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
3
4
  /**
4
5
  * ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
5
6
  *
@@ -25,8 +26,8 @@ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message }
25
26
  */
26
27
  export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
27
28
  tag: string;
28
- constructor();
29
- abstract getCredential(): Promise<{
29
+ constructor(options?: Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "inputSchema" | "outputSchema">);
30
+ get credential(): PromiseOrValue<{
30
31
  url?: string;
31
32
  apiKey?: string;
32
33
  model?: string;
@@ -391,3 +392,16 @@ export interface ChatModelOutputUsage {
391
392
  */
392
393
  aigneHubCredits?: number;
393
394
  }
395
+ export declare const chatModelOutputUsageSchema: z.ZodObject<{
396
+ inputTokens: z.ZodNumber;
397
+ outputTokens: z.ZodNumber;
398
+ aigneHubCredits: z.ZodOptional<z.ZodNumber>;
399
+ }, "strip", z.ZodTypeAny, {
400
+ inputTokens: number;
401
+ outputTokens: number;
402
+ aigneHubCredits?: number | undefined;
403
+ }, {
404
+ inputTokens: number;
405
+ outputTokens: number;
406
+ aigneHubCredits?: number | undefined;
407
+ }>;
@@ -0,0 +1,21 @@
1
+ import { type ZodObject, type ZodType } from "zod";
2
+ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
4
+ import { type ImageModel, type ImageModelOutput } from "./image-model.js";
5
+ export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
6
+ model?: ImageModel;
7
+ instructions: string | PromptBuilder;
8
+ modelOptions?: Record<string, any>;
9
+ }
10
+ export declare const imageAgentOptionsSchema: ZodObject<{
11
+ [key in keyof ImageAgentOptions]: ZodType<ImageAgentOptions[key]>;
12
+ }>;
13
+ export declare class ImageAgent<I extends Message = any, O extends ImageModelOutput = any> extends Agent<I, O> {
14
+ tag: string;
15
+ static from<I extends Message = any, O extends ImageModelOutput = any>(options: ImageAgentOptions<I, O>): ImageAgent<I, O>;
16
+ constructor(options: ImageAgentOptions<I, O>);
17
+ model?: ImageModel;
18
+ instructions: PromptBuilder;
19
+ modelOptions?: Record<string, any>;
20
+ process(input: I, options: AgentInvokeOptions): Promise<O>;
21
+ }
@@ -0,0 +1,115 @@
1
+ import { z } from "zod";
2
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
4
+ import { type ChatModelOutputUsage } from "./chat-model.js";
5
+ export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends AgentOptions<I, O> {
6
+ }
7
+ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Agent<I, O> {
8
+ tag: string;
9
+ constructor(options?: ImageModelOptions<I, O>);
10
+ get credential(): PromiseOrValue<{
11
+ url?: string;
12
+ apiKey?: string;
13
+ model?: string;
14
+ }>;
15
+ protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
16
+ protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
17
+ abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
18
+ }
19
+ export interface ImageModelInput extends Message {
20
+ model?: string;
21
+ image?: string | string[];
22
+ prompt: string;
23
+ n?: number;
24
+ responseFormat?: "url" | "base64";
25
+ }
26
+ export declare const imageModelInputSchema: z.ZodObject<{
27
+ model: z.ZodOptional<z.ZodString>;
28
+ image: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
29
+ prompt: z.ZodString;
30
+ n: z.ZodOptional<z.ZodNumber>;
31
+ responseFormat: z.ZodOptional<z.ZodEnum<["url", "base64"]>>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ prompt: string;
34
+ model?: string | undefined;
35
+ responseFormat?: "url" | "base64" | undefined;
36
+ image?: string | string[] | undefined;
37
+ n?: number | undefined;
38
+ }, {
39
+ prompt: string;
40
+ model?: string | undefined;
41
+ responseFormat?: "url" | "base64" | undefined;
42
+ image?: string | string[] | undefined;
43
+ n?: number | undefined;
44
+ }>;
45
+ export interface ImageModelOutput extends Message {
46
+ images: ImageModelOutputImage[];
47
+ /**
48
+ * Token usage statistics
49
+ */
50
+ usage?: ChatModelOutputUsage;
51
+ /**
52
+ * Model name or version used
53
+ */
54
+ model?: string;
55
+ }
56
+ export type ImageModelOutputImage = ImageModelOutputImageUrl | ImageModelOutputImageBase64;
57
+ export interface ImageModelOutputImageUrl {
58
+ url: string;
59
+ }
60
+ export interface ImageModelOutputImageBase64 {
61
+ base64: string;
62
+ }
63
+ export declare const imageModelOutputSchema: z.ZodObject<{
64
+ images: z.ZodArray<z.ZodUnion<[z.ZodObject<{
65
+ url: z.ZodString;
66
+ }, "strip", z.ZodTypeAny, {
67
+ url: string;
68
+ }, {
69
+ url: string;
70
+ }>, z.ZodObject<{
71
+ base64: z.ZodString;
72
+ }, "strip", z.ZodTypeAny, {
73
+ base64: string;
74
+ }, {
75
+ base64: string;
76
+ }>]>, "many">;
77
+ usage: z.ZodOptional<z.ZodObject<{
78
+ inputTokens: z.ZodNumber;
79
+ outputTokens: z.ZodNumber;
80
+ aigneHubCredits: z.ZodOptional<z.ZodNumber>;
81
+ }, "strip", z.ZodTypeAny, {
82
+ inputTokens: number;
83
+ outputTokens: number;
84
+ aigneHubCredits?: number | undefined;
85
+ }, {
86
+ inputTokens: number;
87
+ outputTokens: number;
88
+ aigneHubCredits?: number | undefined;
89
+ }>>;
90
+ model: z.ZodOptional<z.ZodString>;
91
+ }, "strip", z.ZodTypeAny, {
92
+ images: ({
93
+ url: string;
94
+ } | {
95
+ base64: string;
96
+ })[];
97
+ model?: string | undefined;
98
+ usage?: {
99
+ inputTokens: number;
100
+ outputTokens: number;
101
+ aigneHubCredits?: number | undefined;
102
+ } | undefined;
103
+ }, {
104
+ images: ({
105
+ url: string;
106
+ } | {
107
+ base64: string;
108
+ })[];
109
+ model?: string | undefined;
110
+ usage?: {
111
+ inputTokens: number;
112
+ outputTokens: number;
113
+ aigneHubCredits?: number | undefined;
114
+ } | undefined;
115
+ }>;
@@ -1,6 +1,7 @@
1
1
  import { AIGNEObserver } from "@aigne/observability-api";
2
2
  import type { Agent, AgentResponse, AgentResponseStream, Message } from "../agents/agent.js";
3
3
  import type { ChatModel } from "../agents/chat-model.js";
4
+ import type { ImageModel } from "../agents/image-model.js";
4
5
  import type { UserAgent } from "../agents/user-agent.js";
5
6
  import { type LoadOptions } from "../loader/index.js";
6
7
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
@@ -27,6 +28,10 @@ export interface AIGNEOptions {
27
28
  * Global model to use for all agents not specifying a model.
28
29
  */
29
30
  model?: ChatModel;
31
+ /**
32
+ * Optional image model to use for image processing tasks.
33
+ */
34
+ imageModel?: ImageModel;
30
35
  /**
31
36
  * Skills to use for the AIGNE instance.
32
37
  */
@@ -71,7 +76,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
71
76
  * @param options - Options to override the loaded configuration.
72
77
  * @returns A fully initialized AIGNE instance with configured agents and skills.
73
78
  */
74
- static load(path: string, options: AIGNEOptions & Omit<LoadOptions, "path">): Promise<AIGNE>;
79
+ static load(path: string, options?: Omit<AIGNEOptions, keyof LoadOptions> & LoadOptions): Promise<AIGNE>;
75
80
  /**
76
81
  * Creates a new AIGNE instance with the specified options.
77
82
  *
@@ -94,6 +99,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
94
99
  * Global model to use for all agents that don't specify their own model.
95
100
  */
96
101
  model?: ChatModel;
102
+ /**
103
+ * Optional image model to use for image processing tasks.
104
+ */
105
+ imageModel?: ImageModel;
97
106
  /**
98
107
  * Usage limits applied to this AIGNE instance's execution.
99
108
  */
@@ -3,6 +3,7 @@ import type { Span } from "@opentelemetry/api";
3
3
  import { Emitter } from "strict-event-emitter";
4
4
  import { type Agent, type AgentHooks, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
5
5
  import type { ChatModel } from "../agents/chat-model.js";
6
+ import type { ImageModel } from "../agents/image-model.js";
6
7
  import { UserAgent } from "../agents/user-agent.js";
7
8
  import type { Memory } from "../memory/memory.js";
8
9
  import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
@@ -73,6 +74,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
73
74
  parentId?: string;
74
75
  rootId: string;
75
76
  model?: ChatModel;
77
+ imageModel?: ImageModel;
76
78
  skills?: Agent[];
77
79
  agents: Agent[];
78
80
  observer?: AIGNEObserver;
@@ -155,6 +157,7 @@ export declare class AIGNEContext implements Context {
155
157
  readonly internal: AIGNEContextShared;
156
158
  get messageQueue(): MessageQueue;
157
159
  get model(): ChatModel | undefined;
160
+ get imageModel(): ImageModel<import("../agents/image-model.js").ImageModelInput, import("../agents/image-model.js").ImageModelOutput> | undefined;
158
161
  get skills(): Agent<any, any>[] | undefined;
159
162
  get agents(): Agent<any, any>[];
160
163
  get observer(): AIGNEObserver | undefined;
@@ -187,13 +190,14 @@ export declare class AIGNEContext implements Context {
187
190
  declare class AIGNEContextShared {
188
191
  private readonly parent?;
189
192
  spans: Span[];
190
- constructor(parent?: (Pick<Context, "model" | "agents" | "skills" | "limits" | "observer"> & {
193
+ constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer"> & {
191
194
  messageQueue?: MessageQueue;
192
195
  events?: Emitter<any>;
193
196
  }) | undefined);
194
197
  readonly messageQueue: MessageQueue;
195
198
  readonly events: Emitter<any>;
196
199
  get model(): ChatModel | undefined;
200
+ get imageModel(): ImageModel<import("../agents/image-model.js").ImageModelInput, import("../agents/image-model.js").ImageModelOutput> | undefined;
197
201
  get skills(): Agent<any, any>[] | undefined;
198
202
  get agents(): Agent<any, any>[];
199
203
  get observer(): AIGNEObserver | undefined;
@@ -2,6 +2,8 @@ export * from "./agents/agent.js";
2
2
  export * from "./agents/ai-agent.js";
3
3
  export * from "./agents/chat-model.js";
4
4
  export * from "./agents/guide-rail-agent.js";
5
+ export * from "./agents/image-agent.js";
6
+ export * from "./agents/image-model.js";
5
7
  export * from "./agents/mcp-agent.js";
6
8
  export * from "./agents/team-agent.js";
7
9
  export * from "./agents/transform-agent.js";
@@ -39,6 +39,11 @@ export interface AIAgentSchema extends BaseAgentSchema {
39
39
  outputKey?: string;
40
40
  toolChoice?: AIAgentToolChoice;
41
41
  }
42
+ export interface ImageAgentSchema extends BaseAgentSchema {
43
+ type: "image";
44
+ instructions: string;
45
+ modelOptions?: Record<string, any>;
46
+ }
42
47
  export interface MCPAgentSchema extends BaseAgentSchema {
43
48
  type: "mcp";
44
49
  url?: string;
@@ -64,6 +69,6 @@ export interface FunctionAgentSchema extends BaseAgentSchema {
64
69
  type: "function";
65
70
  process: FunctionAgentFn;
66
71
  }
67
- export type AgentSchema = AIAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema;
72
+ export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema;
68
73
  export declare function parseAgentFile(path: string, data: object): Promise<AgentSchema>;
69
74
  export declare function loadAgentFromYamlFile(path: string): Promise<AgentSchema>;