@aigne/core 1.50.1 → 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.
- package/CHANGELOG.md +28 -0
- package/lib/cjs/agents/agent.d.ts +5 -0
- package/lib/cjs/agents/agent.js +10 -1
- package/lib/cjs/agents/chat-model.d.ts +17 -3
- package/lib/cjs/agents/chat-model.js +10 -4
- package/lib/cjs/agents/image-agent.d.ts +21 -0
- package/lib/cjs/agents/image-agent.js +43 -0
- package/lib/cjs/agents/image-model.d.ts +115 -0
- package/lib/cjs/agents/image-model.js +60 -0
- package/lib/cjs/aigne/aigne.d.ts +10 -1
- package/lib/cjs/aigne/aigne.js +10 -6
- package/lib/cjs/aigne/context.d.ts +5 -1
- package/lib/cjs/aigne/context.js +6 -0
- package/lib/cjs/aigne/usage.d.ts +2 -0
- package/lib/cjs/aigne/usage.js +14 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/loader/agent-yaml.d.ts +8 -2
- package/lib/cjs/loader/agent-yaml.js +19 -9
- package/lib/cjs/loader/index.d.ts +46 -44
- package/lib/cjs/loader/index.js +35 -12
- package/lib/cjs/prompt/prompt-builder.d.ts +3 -0
- package/lib/cjs/prompt/prompt-builder.js +8 -0
- package/lib/cjs/utils/camelize.d.ts +7 -1
- package/lib/cjs/utils/camelize.js +30 -13
- package/lib/cjs/utils/type-utils.d.ts +1 -1
- package/lib/dts/agents/agent.d.ts +5 -0
- package/lib/dts/agents/chat-model.d.ts +17 -3
- package/lib/dts/agents/image-agent.d.ts +21 -0
- package/lib/dts/agents/image-model.d.ts +115 -0
- package/lib/dts/aigne/aigne.d.ts +10 -1
- package/lib/dts/aigne/context.d.ts +5 -1
- package/lib/dts/aigne/usage.d.ts +2 -0
- package/lib/dts/index.d.ts +2 -0
- package/lib/dts/loader/agent-yaml.d.ts +8 -2
- package/lib/dts/loader/index.d.ts +46 -44
- package/lib/dts/prompt/prompt-builder.d.ts +3 -0
- package/lib/dts/utils/camelize.d.ts +7 -1
- package/lib/dts/utils/type-utils.d.ts +1 -1
- package/lib/esm/agents/agent.d.ts +5 -0
- package/lib/esm/agents/agent.js +10 -1
- package/lib/esm/agents/chat-model.d.ts +17 -3
- package/lib/esm/agents/chat-model.js +9 -3
- package/lib/esm/agents/image-agent.d.ts +21 -0
- package/lib/esm/agents/image-agent.js +36 -0
- package/lib/esm/agents/image-model.d.ts +115 -0
- package/lib/esm/agents/image-model.js +56 -0
- package/lib/esm/aigne/aigne.d.ts +10 -1
- package/lib/esm/aigne/aigne.js +10 -6
- package/lib/esm/aigne/context.d.ts +5 -1
- package/lib/esm/aigne/context.js +6 -0
- package/lib/esm/aigne/usage.d.ts +2 -0
- package/lib/esm/aigne/usage.js +13 -0
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/loader/agent-yaml.d.ts +8 -2
- package/lib/esm/loader/agent-yaml.js +19 -9
- package/lib/esm/loader/index.d.ts +46 -44
- package/lib/esm/loader/index.js +36 -13
- package/lib/esm/prompt/prompt-builder.d.ts +3 -0
- package/lib/esm/prompt/prompt-builder.js +8 -0
- package/lib/esm/utils/camelize.d.ts +7 -1
- package/lib/esm/utils/camelize.js +29 -13
- package/lib/esm/utils/type-utils.d.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.53.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.52.0...core-v1.53.0) (2025-08-20)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add ImageModel/ImageAgent support ([#383](https://github.com/AIGNE-io/aigne-framework/issues/383)) ([96a2093](https://github.com/AIGNE-io/aigne-framework/commit/96a209368d91d98f47db6de1e404640368a86fa8))
|
|
9
|
+
|
|
10
|
+
## [1.52.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.51.0...core-v1.52.0) (2025-08-20)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **agents:** add async memory recording option ([#385](https://github.com/AIGNE-io/aigne-framework/issues/385)) ([573acdb](https://github.com/AIGNE-io/aigne-framework/commit/573acdb617434e6699b2e07db942e6336706d27f))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Dependencies
|
|
19
|
+
|
|
20
|
+
* The following workspace dependencies were updated
|
|
21
|
+
* dependencies
|
|
22
|
+
* @aigne/observability-api bumped to 0.9.1
|
|
23
|
+
|
|
24
|
+
## [1.51.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.50.1...core-v1.51.0) (2025-08-18)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* **cli:** support hide or collapse task for agents in CLI ([#381](https://github.com/AIGNE-io/aigne-framework/issues/381)) ([05b372d](https://github.com/AIGNE-io/aigne-framework/commit/05b372d431a862f7cdfa2a90bb4b7b2379bf97ab))
|
|
30
|
+
|
|
3
31
|
## [1.50.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.50.0...core-v1.50.1) (2025-08-16)
|
|
4
32
|
|
|
5
33
|
|
|
@@ -33,6 +33,7 @@ export type SubscribeTopic = string | string[];
|
|
|
33
33
|
* @template O The agent output message type
|
|
34
34
|
*/
|
|
35
35
|
export type PublishTopic<O extends Message> = string | string[] | ((output: O) => PromiseOrValue<Nullish<string | string[]>>);
|
|
36
|
+
export type TaskRenderMode = "hide" | "collapse";
|
|
36
37
|
/**
|
|
37
38
|
* Configuration options for an agent
|
|
38
39
|
*
|
|
@@ -73,6 +74,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
73
74
|
*/
|
|
74
75
|
description?: string;
|
|
75
76
|
taskTitle?: string | ((input: I) => PromiseOrValue<string | undefined>);
|
|
77
|
+
taskRenderMode?: TaskRenderMode;
|
|
76
78
|
/**
|
|
77
79
|
* Zod schema defining the input message structure
|
|
78
80
|
*
|
|
@@ -114,6 +116,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
114
116
|
* One or more memory agents this agent can use
|
|
115
117
|
*/
|
|
116
118
|
memory?: MemoryAgent | MemoryAgent[];
|
|
119
|
+
asyncMemoryRecord?: boolean;
|
|
117
120
|
/**
|
|
118
121
|
* Maximum number of memory items to retrieve
|
|
119
122
|
*/
|
|
@@ -197,6 +200,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
197
200
|
* List of memories this agent can use
|
|
198
201
|
*/
|
|
199
202
|
readonly memories: MemoryAgent[];
|
|
203
|
+
asyncMemoryRecord?: boolean;
|
|
200
204
|
tag?: string;
|
|
201
205
|
/**
|
|
202
206
|
* Maximum number of memory items to retrieve
|
|
@@ -259,6 +263,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
259
263
|
readonly description?: string;
|
|
260
264
|
taskTitle?: string | ((input: Message) => PromiseOrValue<string | undefined>);
|
|
261
265
|
renderTaskTitle(input: I): Promise<string | undefined>;
|
|
266
|
+
taskRenderMode?: TaskRenderMode;
|
|
262
267
|
private readonly _inputSchema?;
|
|
263
268
|
defaultInput?: Partial<{
|
|
264
269
|
[key in keyof I]: {
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -78,6 +78,7 @@ exports.agentOptionsSchema = zod_1.z.object({
|
|
|
78
78
|
skills: zod_1.z.array(zod_1.z.union([zod_1.z.custom(), zod_1.z.custom()])).optional(),
|
|
79
79
|
disableEvents: zod_1.z.boolean().optional(),
|
|
80
80
|
memory: zod_1.z.union([zod_1.z.custom(), zod_1.z.array(zod_1.z.custom())]).optional(),
|
|
81
|
+
asyncMemoryRecord: zod_1.z.boolean().optional(),
|
|
81
82
|
maxRetrieveMemoryCount: zod_1.z.number().optional(),
|
|
82
83
|
hooks: zod_1.z.union([zod_1.z.array(hooksSchema), hooksSchema]).optional(),
|
|
83
84
|
guideRails: zod_1.z.array(zod_1.z.custom()).optional(),
|
|
@@ -111,6 +112,7 @@ class Agent {
|
|
|
111
112
|
this.alias = options.alias;
|
|
112
113
|
this.description = options.description;
|
|
113
114
|
this.taskTitle = options.taskTitle;
|
|
115
|
+
this.taskRenderMode = options.taskRenderMode;
|
|
114
116
|
if (inputSchema)
|
|
115
117
|
checkAgentInputOutputSchema(inputSchema);
|
|
116
118
|
if (outputSchema)
|
|
@@ -130,6 +132,7 @@ class Agent {
|
|
|
130
132
|
else if (options.memory) {
|
|
131
133
|
this.memories.push(options.memory);
|
|
132
134
|
}
|
|
135
|
+
this.asyncMemoryRecord = options.asyncMemoryRecord;
|
|
133
136
|
this.maxRetrieveMemoryCount = options.maxRetrieveMemoryCount;
|
|
134
137
|
this.hooks = (0, type_utils_js_1.flat)(options.hooks);
|
|
135
138
|
this.guideRails = options.guideRails;
|
|
@@ -138,6 +141,7 @@ class Agent {
|
|
|
138
141
|
* List of memories this agent can use
|
|
139
142
|
*/
|
|
140
143
|
memories = [];
|
|
144
|
+
asyncMemoryRecord;
|
|
141
145
|
tag;
|
|
142
146
|
/**
|
|
143
147
|
* Maximum number of memory items to retrieve
|
|
@@ -209,6 +213,7 @@ class Agent {
|
|
|
209
213
|
return;
|
|
210
214
|
return nunjucks_1.default.renderString(s, { ...input });
|
|
211
215
|
}
|
|
216
|
+
taskRenderMode;
|
|
212
217
|
_inputSchema;
|
|
213
218
|
defaultInput;
|
|
214
219
|
_outputSchema;
|
|
@@ -598,7 +603,11 @@ class Agent {
|
|
|
598
603
|
async postprocess(input, output, options) {
|
|
599
604
|
this.checkContextStatus(options);
|
|
600
605
|
this.publishToTopics(output, options);
|
|
601
|
-
|
|
606
|
+
const memory = this.recordMemories({ content: [{ input, output: (0, types_js_1.replaceTransferAgentToName)(output), source: this.name }] }, options).catch((error) => {
|
|
607
|
+
logger_js_1.logger.error(`Agent ${this.name} failed to record memories:`, error);
|
|
608
|
+
});
|
|
609
|
+
if (!this.asyncMemoryRecord)
|
|
610
|
+
await memory;
|
|
602
611
|
}
|
|
603
612
|
async publishToTopics(output, options) {
|
|
604
613
|
const publishTopics = typeof this.publishTopic === "function" ? await this.publishTopic(output) : this.publishTopic;
|
|
@@ -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
|
-
|
|
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
|
+
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChatModel = void 0;
|
|
3
|
+
exports.chatModelOutputUsageSchema = exports.ChatModel = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const agent_js_1 = require("./agent.js");
|
|
6
6
|
/**
|
|
@@ -28,12 +28,16 @@ const agent_js_1 = require("./agent.js");
|
|
|
28
28
|
*/
|
|
29
29
|
class ChatModel extends agent_js_1.Agent {
|
|
30
30
|
tag = "ChatModelAgent";
|
|
31
|
-
constructor() {
|
|
31
|
+
constructor(options) {
|
|
32
32
|
super({
|
|
33
|
+
...options,
|
|
33
34
|
inputSchema: chatModelInputSchema,
|
|
34
35
|
outputSchema: chatModelOutputSchema,
|
|
35
36
|
});
|
|
36
37
|
}
|
|
38
|
+
get credential() {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
37
41
|
/**
|
|
38
42
|
* Indicates whether the model supports parallel tool calls
|
|
39
43
|
*
|
|
@@ -138,6 +142,8 @@ class ChatModel extends agent_js_1.Agent {
|
|
|
138
142
|
if (usage) {
|
|
139
143
|
options.context.usage.outputTokens += usage.outputTokens;
|
|
140
144
|
options.context.usage.inputTokens += usage.inputTokens;
|
|
145
|
+
if (usage.aigneHubCredits)
|
|
146
|
+
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
}
|
|
@@ -215,7 +221,7 @@ const chatModelOutputToolCallSchema = zod_1.z.object({
|
|
|
215
221
|
arguments: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
|
|
216
222
|
}),
|
|
217
223
|
});
|
|
218
|
-
|
|
224
|
+
exports.chatModelOutputUsageSchema = zod_1.z.object({
|
|
219
225
|
inputTokens: zod_1.z.number(),
|
|
220
226
|
outputTokens: zod_1.z.number(),
|
|
221
227
|
aigneHubCredits: zod_1.z.number().optional(),
|
|
@@ -224,6 +230,6 @@ const chatModelOutputSchema = zod_1.z.object({
|
|
|
224
230
|
text: zod_1.z.string().optional(),
|
|
225
231
|
json: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
|
|
226
232
|
toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
|
|
227
|
-
usage: chatModelOutputUsageSchema.optional(),
|
|
233
|
+
usage: exports.chatModelOutputUsageSchema.optional(),
|
|
228
234
|
model: zod_1.z.string().optional(),
|
|
229
235
|
});
|
|
@@ -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,43 @@
|
|
|
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.ImageAgent = exports.imageAgentOptionsSchema = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
9
|
+
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
10
|
+
const agent_js_1 = require("./agent.js");
|
|
11
|
+
const image_model_js_1 = require("./image-model.js");
|
|
12
|
+
exports.imageAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
|
|
13
|
+
model: zod_1.default.custom().optional(),
|
|
14
|
+
instructions: zod_1.default.union([zod_1.default.string(), zod_1.default.custom()]),
|
|
15
|
+
modelOptions: zod_1.default.record(zod_1.default.any()).optional(),
|
|
16
|
+
});
|
|
17
|
+
class ImageAgent extends agent_js_1.Agent {
|
|
18
|
+
tag = "ImageAgent";
|
|
19
|
+
static from(options) {
|
|
20
|
+
return new ImageAgent(options);
|
|
21
|
+
}
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super({ ...options, outputSchema: image_model_js_1.imageModelOutputSchema });
|
|
24
|
+
(0, type_utils_js_1.checkArguments)("ImageAgent", exports.imageAgentOptionsSchema, options);
|
|
25
|
+
this.model = options.model;
|
|
26
|
+
this.instructions =
|
|
27
|
+
typeof options.instructions === "string"
|
|
28
|
+
? prompt_builder_js_1.PromptBuilder.from(options.instructions)
|
|
29
|
+
: options.instructions;
|
|
30
|
+
this.modelOptions = options.modelOptions;
|
|
31
|
+
}
|
|
32
|
+
model;
|
|
33
|
+
instructions;
|
|
34
|
+
modelOptions;
|
|
35
|
+
async process(input, options) {
|
|
36
|
+
const model = this.model ?? options.context.imageModel;
|
|
37
|
+
if (!model)
|
|
38
|
+
throw new Error("image model is required to run ImageAgent");
|
|
39
|
+
const { prompt } = await this.instructions.buildImagePrompt({ input });
|
|
40
|
+
return (await options.context.invoke(model, { ...input, ...this.modelOptions, prompt }, { ...options, streaming: false }));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ImageAgent = ImageAgent;
|
|
@@ -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
|
+
}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageModelOutputSchema = exports.imageModelInputSchema = exports.ImageModel = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const agent_js_1 = require("./agent.js");
|
|
6
|
+
const chat_model_js_1 = require("./chat-model.js");
|
|
7
|
+
class ImageModel extends agent_js_1.Agent {
|
|
8
|
+
tag = "ImageModelAgent";
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super({
|
|
11
|
+
inputSchema: exports.imageModelInputSchema,
|
|
12
|
+
outputSchema: exports.imageModelOutputSchema,
|
|
13
|
+
...options,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
get credential() {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
async preprocess(input, options) {
|
|
20
|
+
super.preprocess(input, options);
|
|
21
|
+
const { limits, usage } = options.context;
|
|
22
|
+
const usedTokens = usage.outputTokens + usage.inputTokens;
|
|
23
|
+
if (limits?.maxTokens && usedTokens >= limits.maxTokens) {
|
|
24
|
+
throw new Error(`Exceeded max tokens ${usedTokens}/${limits.maxTokens}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async postprocess(input, output, options) {
|
|
28
|
+
super.postprocess(input, output, options);
|
|
29
|
+
const { usage } = output;
|
|
30
|
+
if (usage) {
|
|
31
|
+
options.context.usage.outputTokens += usage.outputTokens;
|
|
32
|
+
options.context.usage.inputTokens += usage.inputTokens;
|
|
33
|
+
if (usage.aigneHubCredits)
|
|
34
|
+
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ImageModel = ImageModel;
|
|
39
|
+
exports.imageModelInputSchema = zod_1.z.object({
|
|
40
|
+
model: zod_1.z.string().optional(),
|
|
41
|
+
image: zod_1.z
|
|
42
|
+
.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())])
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("Image URL or base64 string(s) used for editing"),
|
|
45
|
+
prompt: zod_1.z.string(),
|
|
46
|
+
n: zod_1.z.number().int().min(1).optional(),
|
|
47
|
+
responseFormat: zod_1.z.enum(["url", "base64"]).optional(),
|
|
48
|
+
});
|
|
49
|
+
exports.imageModelOutputSchema = zod_1.z.object({
|
|
50
|
+
images: zod_1.z.array(zod_1.z.union([
|
|
51
|
+
zod_1.z.object({
|
|
52
|
+
url: zod_1.z.string(),
|
|
53
|
+
}),
|
|
54
|
+
zod_1.z.object({
|
|
55
|
+
base64: zod_1.z.string(),
|
|
56
|
+
}),
|
|
57
|
+
])),
|
|
58
|
+
usage: chat_model_js_1.chatModelOutputUsageSchema.optional(),
|
|
59
|
+
model: zod_1.z.string().optional(),
|
|
60
|
+
});
|
package/lib/cjs/aigne/aigne.d.ts
CHANGED
|
@@ -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
|
|
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
|
*/
|
package/lib/cjs/aigne/aigne.js
CHANGED
|
@@ -28,15 +28,13 @@ class AIGNE {
|
|
|
28
28
|
* @param options - Options to override the loaded configuration.
|
|
29
29
|
* @returns A fully initialized AIGNE instance with configured agents and skills.
|
|
30
30
|
*/
|
|
31
|
-
static async load(path, options) {
|
|
32
|
-
const {
|
|
31
|
+
static async load(path, options = {}) {
|
|
32
|
+
const { agents = [], skills = [], model, imageModel, ...aigne } = await (0, index_js_1.load)(path, options);
|
|
33
33
|
return new AIGNE({
|
|
34
34
|
...aigne,
|
|
35
35
|
...options,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
name: options?.name || aigne.name || undefined,
|
|
39
|
-
description: options?.description || aigne.description || undefined,
|
|
36
|
+
model,
|
|
37
|
+
imageModel,
|
|
40
38
|
agents: agents.concat(options?.agents ?? []),
|
|
41
39
|
skills: skills.concat(options?.skills ?? []),
|
|
42
40
|
});
|
|
@@ -53,6 +51,7 @@ class AIGNE {
|
|
|
53
51
|
this.name = options?.name;
|
|
54
52
|
this.description = options?.description;
|
|
55
53
|
this.model = options?.model;
|
|
54
|
+
this.imageModel = options?.imageModel;
|
|
56
55
|
this.limits = options?.limits;
|
|
57
56
|
this.observer =
|
|
58
57
|
process.env.AIGNE_OBSERVABILITY_DISABLED === "true"
|
|
@@ -85,6 +84,10 @@ class AIGNE {
|
|
|
85
84
|
* Global model to use for all agents that don't specify their own model.
|
|
86
85
|
*/
|
|
87
86
|
model;
|
|
87
|
+
/**
|
|
88
|
+
* Optional image model to use for image processing tasks.
|
|
89
|
+
*/
|
|
90
|
+
imageModel;
|
|
88
91
|
/**
|
|
89
92
|
* Usage limits applied to this AIGNE instance's execution.
|
|
90
93
|
*/
|
|
@@ -223,6 +226,7 @@ class AIGNE {
|
|
|
223
226
|
exports.AIGNE = AIGNE;
|
|
224
227
|
const aigneOptionsSchema = zod_1.z.object({
|
|
225
228
|
model: zod_1.z.custom().optional(),
|
|
229
|
+
imageModel: zod_1.z.custom().optional(),
|
|
226
230
|
skills: zod_1.z.array(zod_1.z.custom()).optional(),
|
|
227
231
|
agents: zod_1.z.array(zod_1.z.custom()).optional(),
|
|
228
232
|
observer: zod_1.z.custom().optional(),
|
|
@@ -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;
|
package/lib/cjs/aigne/context.js
CHANGED
|
@@ -61,6 +61,9 @@ class AIGNEContext {
|
|
|
61
61
|
get model() {
|
|
62
62
|
return this.internal.model;
|
|
63
63
|
}
|
|
64
|
+
get imageModel() {
|
|
65
|
+
return this.internal.imageModel;
|
|
66
|
+
}
|
|
64
67
|
get skills() {
|
|
65
68
|
return this.internal.skills;
|
|
66
69
|
}
|
|
@@ -306,6 +309,9 @@ class AIGNEContextShared {
|
|
|
306
309
|
get model() {
|
|
307
310
|
return this.parent?.model;
|
|
308
311
|
}
|
|
312
|
+
get imageModel() {
|
|
313
|
+
return this.parent?.imageModel;
|
|
314
|
+
}
|
|
309
315
|
get skills() {
|
|
310
316
|
return this.parent?.skills;
|
|
311
317
|
}
|
package/lib/cjs/aigne/usage.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
export interface ContextUsage {
|
|
5
5
|
inputTokens: number;
|
|
6
6
|
outputTokens: number;
|
|
7
|
+
aigneHubCredits: number;
|
|
7
8
|
agentCalls: number;
|
|
8
9
|
duration: number;
|
|
9
10
|
}
|
|
@@ -19,3 +20,4 @@ export interface ContextLimits {
|
|
|
19
20
|
maxAgentInvokes?: number;
|
|
20
21
|
timeout?: number;
|
|
21
22
|
}
|
|
23
|
+
export declare function mergeContextUsage(usage: ContextUsage, additional: Partial<ContextUsage>): void;
|
package/lib/cjs/aigne/usage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.newEmptyContextUsage = newEmptyContextUsage;
|
|
4
|
+
exports.mergeContextUsage = mergeContextUsage;
|
|
4
5
|
/**
|
|
5
6
|
* @hidden
|
|
6
7
|
*/
|
|
@@ -8,7 +9,20 @@ function newEmptyContextUsage() {
|
|
|
8
9
|
return {
|
|
9
10
|
inputTokens: 0,
|
|
10
11
|
outputTokens: 0,
|
|
12
|
+
aigneHubCredits: 0,
|
|
11
13
|
agentCalls: 0,
|
|
12
14
|
duration: 0,
|
|
13
15
|
};
|
|
14
16
|
}
|
|
17
|
+
function mergeContextUsage(usage, additional) {
|
|
18
|
+
if (additional.inputTokens)
|
|
19
|
+
usage.inputTokens += additional.inputTokens;
|
|
20
|
+
if (additional.outputTokens)
|
|
21
|
+
usage.outputTokens += additional.outputTokens;
|
|
22
|
+
if (additional.aigneHubCredits)
|
|
23
|
+
usage.aigneHubCredits += additional.aigneHubCredits;
|
|
24
|
+
if (additional.agentCalls)
|
|
25
|
+
usage.agentCalls += additional.agentCalls;
|
|
26
|
+
if (additional.duration)
|
|
27
|
+
usage.duration += additional.duration;
|
|
28
|
+
}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -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";
|
package/lib/cjs/index.js
CHANGED
|
@@ -18,6 +18,8 @@ __exportStar(require("./agents/agent.js"), exports);
|
|
|
18
18
|
__exportStar(require("./agents/ai-agent.js"), exports);
|
|
19
19
|
__exportStar(require("./agents/chat-model.js"), exports);
|
|
20
20
|
__exportStar(require("./agents/guide-rail-agent.js"), exports);
|
|
21
|
+
__exportStar(require("./agents/image-agent.js"), exports);
|
|
22
|
+
__exportStar(require("./agents/image-model.js"), exports);
|
|
21
23
|
__exportStar(require("./agents/mcp-agent.js"), exports);
|
|
22
24
|
__exportStar(require("./agents/team-agent.js"), exports);
|
|
23
25
|
__exportStar(require("./agents/transform-agent.js"), exports);
|