@aigne/core 1.72.0-beta.2 → 1.72.0-beta.3
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 +14 -0
- package/lib/cjs/agents/chat-model.d.ts +153 -0
- package/lib/cjs/agents/chat-model.js +35 -1
- package/lib/cjs/agents/image-model.d.ts +10 -0
- package/lib/cjs/agents/video-model.d.ts +10 -0
- package/lib/cjs/aigne/usage.d.ts +4 -0
- package/lib/cjs/aigne/usage.js +6 -0
- package/lib/cjs/loader/agent-yaml.d.ts +4 -0
- package/lib/cjs/loader/agent-yaml.js +15 -5
- package/lib/cjs/prompt/template.d.ts +82 -7
- package/lib/cjs/prompt/template.js +46 -17
- package/lib/dts/agents/chat-model.d.ts +153 -0
- package/lib/dts/agents/image-model.d.ts +10 -0
- package/lib/dts/agents/video-model.d.ts +10 -0
- package/lib/dts/aigne/usage.d.ts +4 -0
- package/lib/dts/loader/agent-yaml.d.ts +4 -0
- package/lib/dts/prompt/template.d.ts +82 -7
- package/lib/esm/agents/chat-model.d.ts +153 -0
- package/lib/esm/agents/chat-model.js +34 -0
- package/lib/esm/agents/image-model.d.ts +10 -0
- package/lib/esm/agents/video-model.d.ts +10 -0
- package/lib/esm/aigne/usage.d.ts +4 -0
- package/lib/esm/aigne/usage.js +6 -0
- package/lib/esm/loader/agent-yaml.d.ts +4 -0
- package/lib/esm/loader/agent-yaml.js +15 -5
- package/lib/esm/prompt/template.d.ts +82 -7
- package/lib/esm/prompt/template.js +46 -17
- package/package.json +4 -4
|
@@ -27,35 +27,38 @@ export declare class ChatMessageTemplate {
|
|
|
27
27
|
content?: ChatModelInputMessage["content"];
|
|
28
28
|
name?: string | undefined;
|
|
29
29
|
options?: FormatOptions | undefined;
|
|
30
|
-
|
|
30
|
+
cacheControl?: ChatModelInputMessage["cacheControl"];
|
|
31
|
+
constructor(role: "system" | "user" | "agent" | "tool", content?: ChatModelInputMessage["content"], name?: string | undefined, options?: FormatOptions | undefined, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
31
32
|
format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<ChatModelInputMessage>;
|
|
32
33
|
}
|
|
33
34
|
export declare class SystemMessageTemplate extends ChatMessageTemplate {
|
|
34
|
-
static from(content: string, name?: string, options?: FormatOptions): SystemMessageTemplate;
|
|
35
|
+
static from(content: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): SystemMessageTemplate;
|
|
35
36
|
}
|
|
36
37
|
export declare class UserMessageTemplate extends ChatMessageTemplate {
|
|
37
|
-
static from(template: ChatModelInputMessageContent, name?: string, options?: FormatOptions): UserMessageTemplate;
|
|
38
|
+
static from(template: ChatModelInputMessageContent, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): UserMessageTemplate;
|
|
38
39
|
}
|
|
39
40
|
export declare class AgentMessageTemplate extends ChatMessageTemplate {
|
|
40
41
|
toolCalls?: ChatModelOutputToolCall[] | undefined;
|
|
41
|
-
static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions): AgentMessageTemplate;
|
|
42
|
-
constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions);
|
|
42
|
+
static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): AgentMessageTemplate;
|
|
43
|
+
constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
43
44
|
format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
|
|
44
45
|
role: "agent" | "system" | "user" | "tool";
|
|
45
46
|
name: string | undefined;
|
|
46
47
|
content: ChatModelInputMessageContent | undefined;
|
|
47
48
|
toolCalls: ChatModelOutputToolCall[] | undefined;
|
|
49
|
+
cacheControl: import("../agents/chat-model.js").CacheControl | undefined;
|
|
48
50
|
}>;
|
|
49
51
|
}
|
|
50
52
|
export declare class ToolMessageTemplate extends ChatMessageTemplate {
|
|
51
53
|
toolCallId: string;
|
|
52
|
-
static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions): ToolMessageTemplate;
|
|
53
|
-
constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions);
|
|
54
|
+
static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): ToolMessageTemplate;
|
|
55
|
+
constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
|
|
54
56
|
format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
|
|
55
57
|
role: "agent" | "system" | "user" | "tool";
|
|
56
58
|
name: string | undefined;
|
|
57
59
|
content: ChatModelInputMessageContent | undefined;
|
|
58
60
|
toolCallId: string;
|
|
61
|
+
cacheControl: import("../agents/chat-model.js").CacheControl | undefined;
|
|
59
62
|
}>;
|
|
60
63
|
}
|
|
61
64
|
export declare class ChatMessagesTemplate {
|
|
@@ -69,26 +72,62 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
69
72
|
role: z.ZodLiteral<"system">;
|
|
70
73
|
content: z.ZodString;
|
|
71
74
|
name: z.ZodOptional<z.ZodString>;
|
|
75
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
76
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
77
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
type: "ephemeral";
|
|
80
|
+
ttl?: "5m" | "1h" | undefined;
|
|
81
|
+
}, {
|
|
82
|
+
type: "ephemeral";
|
|
83
|
+
ttl?: "5m" | "1h" | undefined;
|
|
84
|
+
}>>;
|
|
72
85
|
}, "strip", z.ZodTypeAny, {
|
|
73
86
|
role: "system";
|
|
74
87
|
content: string;
|
|
75
88
|
name?: string | undefined;
|
|
89
|
+
cacheControl?: {
|
|
90
|
+
type: "ephemeral";
|
|
91
|
+
ttl?: "5m" | "1h" | undefined;
|
|
92
|
+
} | undefined;
|
|
76
93
|
}, {
|
|
77
94
|
role: "system";
|
|
78
95
|
content: string;
|
|
79
96
|
name?: string | undefined;
|
|
97
|
+
cacheControl?: {
|
|
98
|
+
type: "ephemeral";
|
|
99
|
+
ttl?: "5m" | "1h" | undefined;
|
|
100
|
+
} | undefined;
|
|
80
101
|
}>, z.ZodObject<{
|
|
81
102
|
role: z.ZodLiteral<"user">;
|
|
82
103
|
content: z.ZodString;
|
|
83
104
|
name: z.ZodOptional<z.ZodString>;
|
|
105
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
106
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
107
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
type: "ephemeral";
|
|
110
|
+
ttl?: "5m" | "1h" | undefined;
|
|
111
|
+
}, {
|
|
112
|
+
type: "ephemeral";
|
|
113
|
+
ttl?: "5m" | "1h" | undefined;
|
|
114
|
+
}>>;
|
|
84
115
|
}, "strip", z.ZodTypeAny, {
|
|
85
116
|
role: "user";
|
|
86
117
|
content: string;
|
|
87
118
|
name?: string | undefined;
|
|
119
|
+
cacheControl?: {
|
|
120
|
+
type: "ephemeral";
|
|
121
|
+
ttl?: "5m" | "1h" | undefined;
|
|
122
|
+
} | undefined;
|
|
88
123
|
}, {
|
|
89
124
|
role: "user";
|
|
90
125
|
content: string;
|
|
91
126
|
name?: string | undefined;
|
|
127
|
+
cacheControl?: {
|
|
128
|
+
type: "ephemeral";
|
|
129
|
+
ttl?: "5m" | "1h" | undefined;
|
|
130
|
+
} | undefined;
|
|
92
131
|
}>, z.ZodObject<{
|
|
93
132
|
role: z.ZodLiteral<"agent">;
|
|
94
133
|
content: z.ZodOptional<z.ZodString>;
|
|
@@ -121,6 +160,16 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
121
160
|
id: string;
|
|
122
161
|
}>, "many">>;
|
|
123
162
|
name: z.ZodOptional<z.ZodString>;
|
|
163
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
165
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
166
|
+
}, "strip", z.ZodTypeAny, {
|
|
167
|
+
type: "ephemeral";
|
|
168
|
+
ttl?: "5m" | "1h" | undefined;
|
|
169
|
+
}, {
|
|
170
|
+
type: "ephemeral";
|
|
171
|
+
ttl?: "5m" | "1h" | undefined;
|
|
172
|
+
}>>;
|
|
124
173
|
}, "strip", z.ZodTypeAny, {
|
|
125
174
|
role: "agent";
|
|
126
175
|
name?: string | undefined;
|
|
@@ -133,6 +182,10 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
133
182
|
type: "function";
|
|
134
183
|
id: string;
|
|
135
184
|
}[] | undefined;
|
|
185
|
+
cacheControl?: {
|
|
186
|
+
type: "ephemeral";
|
|
187
|
+
ttl?: "5m" | "1h" | undefined;
|
|
188
|
+
} | undefined;
|
|
136
189
|
}, {
|
|
137
190
|
role: "agent";
|
|
138
191
|
name?: string | undefined;
|
|
@@ -145,21 +198,43 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
145
198
|
type: "function";
|
|
146
199
|
id: string;
|
|
147
200
|
}[] | undefined;
|
|
201
|
+
cacheControl?: {
|
|
202
|
+
type: "ephemeral";
|
|
203
|
+
ttl?: "5m" | "1h" | undefined;
|
|
204
|
+
} | undefined;
|
|
148
205
|
}>, z.ZodObject<{
|
|
149
206
|
role: z.ZodLiteral<"tool">;
|
|
150
207
|
content: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>, string, string | Record<string, unknown>>;
|
|
151
208
|
toolCallId: z.ZodString;
|
|
152
209
|
name: z.ZodOptional<z.ZodString>;
|
|
210
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
211
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
212
|
+
ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
213
|
+
}, "strip", z.ZodTypeAny, {
|
|
214
|
+
type: "ephemeral";
|
|
215
|
+
ttl?: "5m" | "1h" | undefined;
|
|
216
|
+
}, {
|
|
217
|
+
type: "ephemeral";
|
|
218
|
+
ttl?: "5m" | "1h" | undefined;
|
|
219
|
+
}>>;
|
|
153
220
|
}, "strip", z.ZodTypeAny, {
|
|
154
221
|
role: "tool";
|
|
155
222
|
content: string;
|
|
156
223
|
toolCallId: string;
|
|
157
224
|
name?: string | undefined;
|
|
225
|
+
cacheControl?: {
|
|
226
|
+
type: "ephemeral";
|
|
227
|
+
ttl?: "5m" | "1h" | undefined;
|
|
228
|
+
} | undefined;
|
|
158
229
|
}, {
|
|
159
230
|
role: "tool";
|
|
160
231
|
content: string | Record<string, unknown>;
|
|
161
232
|
toolCallId: string;
|
|
162
233
|
name?: string | undefined;
|
|
234
|
+
cacheControl?: {
|
|
235
|
+
type: "ephemeral";
|
|
236
|
+
ttl?: "5m" | "1h" | undefined;
|
|
237
|
+
} | undefined;
|
|
163
238
|
}>]>;
|
|
164
239
|
export declare function safeParseChatMessages(messages: unknown): ChatMessageTemplate[] | undefined;
|
|
165
240
|
export declare function parseChatMessages(messages: (z.infer<typeof chatMessageSchema> & {
|
|
@@ -70,11 +70,13 @@ export class ChatMessageTemplate {
|
|
|
70
70
|
content;
|
|
71
71
|
name;
|
|
72
72
|
options;
|
|
73
|
-
|
|
73
|
+
cacheControl;
|
|
74
|
+
constructor(role, content, name, options, cacheControl) {
|
|
74
75
|
this.role = role;
|
|
75
76
|
this.content = content;
|
|
76
77
|
this.name = name;
|
|
77
78
|
this.options = options;
|
|
79
|
+
this.cacheControl = cacheControl;
|
|
78
80
|
}
|
|
79
81
|
async format(variables, options) {
|
|
80
82
|
options = { ...this.options, ...omitBy(options ?? {}, (v) => isNil(v)) };
|
|
@@ -93,26 +95,27 @@ export class ChatMessageTemplate {
|
|
|
93
95
|
role: this.role,
|
|
94
96
|
content,
|
|
95
97
|
name: this.name,
|
|
98
|
+
cacheControl: this.cacheControl,
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
export class SystemMessageTemplate extends ChatMessageTemplate {
|
|
100
|
-
static from(content, name, options) {
|
|
101
|
-
return new SystemMessageTemplate("system", content, name, options);
|
|
103
|
+
static from(content, name, options, cacheControl) {
|
|
104
|
+
return new SystemMessageTemplate("system", content, name, options, cacheControl);
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
export class UserMessageTemplate extends ChatMessageTemplate {
|
|
105
|
-
static from(template, name, options) {
|
|
106
|
-
return new UserMessageTemplate("user", template, name, options);
|
|
108
|
+
static from(template, name, options, cacheControl) {
|
|
109
|
+
return new UserMessageTemplate("user", template, name, options, cacheControl);
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
export class AgentMessageTemplate extends ChatMessageTemplate {
|
|
110
113
|
toolCalls;
|
|
111
|
-
static from(template, toolCalls, name, options) {
|
|
112
|
-
return new AgentMessageTemplate(template, toolCalls, name, options);
|
|
114
|
+
static from(template, toolCalls, name, options, cacheControl) {
|
|
115
|
+
return new AgentMessageTemplate(template, toolCalls, name, options, cacheControl);
|
|
113
116
|
}
|
|
114
|
-
constructor(content, toolCalls, name, options) {
|
|
115
|
-
super("agent", content, name, options);
|
|
117
|
+
constructor(content, toolCalls, name, options, cacheControl) {
|
|
118
|
+
super("agent", content, name, options, cacheControl);
|
|
116
119
|
this.toolCalls = toolCalls;
|
|
117
120
|
}
|
|
118
121
|
async format(_variables, _options) {
|
|
@@ -122,16 +125,17 @@ export class AgentMessageTemplate extends ChatMessageTemplate {
|
|
|
122
125
|
// NOTE: agent message should not rendered by template
|
|
123
126
|
content: this.content,
|
|
124
127
|
toolCalls: this.toolCalls,
|
|
128
|
+
cacheControl: this.cacheControl,
|
|
125
129
|
};
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
export class ToolMessageTemplate extends ChatMessageTemplate {
|
|
129
133
|
toolCallId;
|
|
130
|
-
static from(content, toolCallId, name, options) {
|
|
131
|
-
return new ToolMessageTemplate(content, toolCallId, name, options);
|
|
134
|
+
static from(content, toolCallId, name, options, cacheControl) {
|
|
135
|
+
return new ToolMessageTemplate(content, toolCallId, name, options, cacheControl);
|
|
132
136
|
}
|
|
133
|
-
constructor(content, toolCallId, name, options) {
|
|
134
|
-
super("tool", typeof content === "string" ? content : stringify(content), name, options);
|
|
137
|
+
constructor(content, toolCallId, name, options, cacheControl) {
|
|
138
|
+
super("tool", typeof content === "string" ? content : stringify(content), name, options, cacheControl);
|
|
135
139
|
this.toolCallId = toolCallId;
|
|
136
140
|
}
|
|
137
141
|
async format(_variables, _options) {
|
|
@@ -141,6 +145,7 @@ export class ToolMessageTemplate extends ChatMessageTemplate {
|
|
|
141
145
|
// NOTE: tool result should not rendered by template
|
|
142
146
|
content: this.content,
|
|
143
147
|
toolCallId: this.toolCallId,
|
|
148
|
+
cacheControl: this.cacheControl,
|
|
144
149
|
};
|
|
145
150
|
}
|
|
146
151
|
}
|
|
@@ -163,11 +168,23 @@ const systemChatMessageSchema = z.object({
|
|
|
163
168
|
role: z.literal("system"),
|
|
164
169
|
content: z.string(),
|
|
165
170
|
name: z.string().optional(),
|
|
171
|
+
cacheControl: z
|
|
172
|
+
.object({
|
|
173
|
+
type: z.literal("ephemeral"),
|
|
174
|
+
ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
|
|
175
|
+
})
|
|
176
|
+
.optional(),
|
|
166
177
|
});
|
|
167
178
|
const userChatMessageSchema = z.object({
|
|
168
179
|
role: z.literal("user"),
|
|
169
180
|
content: z.string(),
|
|
170
181
|
name: z.string().optional(),
|
|
182
|
+
cacheControl: z
|
|
183
|
+
.object({
|
|
184
|
+
type: z.literal("ephemeral"),
|
|
185
|
+
ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
|
|
186
|
+
})
|
|
187
|
+
.optional(),
|
|
171
188
|
});
|
|
172
189
|
const chatModelOutputToolCallSchema = z.object({
|
|
173
190
|
id: z.string(),
|
|
@@ -182,6 +199,12 @@ const agentChatMessageSchema = z.object({
|
|
|
182
199
|
content: z.string().optional(),
|
|
183
200
|
toolCalls: z.array(chatModelOutputToolCallSchema).optional(),
|
|
184
201
|
name: z.string().optional(),
|
|
202
|
+
cacheControl: z
|
|
203
|
+
.object({
|
|
204
|
+
type: z.literal("ephemeral"),
|
|
205
|
+
ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
|
|
206
|
+
})
|
|
207
|
+
.optional(),
|
|
185
208
|
});
|
|
186
209
|
const toolChatMessageSchema = z.object({
|
|
187
210
|
role: z.literal("tool"),
|
|
@@ -190,6 +213,12 @@ const toolChatMessageSchema = z.object({
|
|
|
190
213
|
.transform((val) => (typeof val !== "string" ? JSON.stringify(val) : val)),
|
|
191
214
|
toolCallId: z.string(),
|
|
192
215
|
name: z.string().optional(),
|
|
216
|
+
cacheControl: z
|
|
217
|
+
.object({
|
|
218
|
+
type: z.literal("ephemeral"),
|
|
219
|
+
ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
|
|
220
|
+
})
|
|
221
|
+
.optional(),
|
|
193
222
|
});
|
|
194
223
|
const chatMessageSchema = z.union([
|
|
195
224
|
systemChatMessageSchema,
|
|
@@ -208,13 +237,13 @@ export function parseChatMessages(messages) {
|
|
|
208
237
|
return messages.map((message) => {
|
|
209
238
|
switch (message.role) {
|
|
210
239
|
case "system":
|
|
211
|
-
return SystemMessageTemplate.from(message.content, message.name, message.options);
|
|
240
|
+
return SystemMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
|
|
212
241
|
case "user":
|
|
213
|
-
return UserMessageTemplate.from(message.content, message.name, message.options);
|
|
242
|
+
return UserMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
|
|
214
243
|
case "agent":
|
|
215
|
-
return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options);
|
|
244
|
+
return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options, message.cacheControl);
|
|
216
245
|
case "tool":
|
|
217
|
-
return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options);
|
|
246
|
+
return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options, message.cacheControl);
|
|
218
247
|
}
|
|
219
248
|
});
|
|
220
249
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.72.0-beta.
|
|
3
|
+
"version": "1.72.0-beta.3",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -93,9 +93,9 @@
|
|
|
93
93
|
"zod-from-json-schema": "^0.0.5",
|
|
94
94
|
"zod-to-json-schema": "^3.24.6",
|
|
95
95
|
"@aigne/afs": "^1.4.0-beta.2",
|
|
96
|
-
"@aigne/
|
|
97
|
-
"@aigne/observability-api": "^0.11.14-beta",
|
|
98
|
-
"@aigne/
|
|
96
|
+
"@aigne/platform-helpers": "^0.6.7-beta",
|
|
97
|
+
"@aigne/observability-api": "^0.11.14-beta.1",
|
|
98
|
+
"@aigne/afs-history": "^1.2.0-beta.2"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@types/bun": "^1.2.22",
|