@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> & {
|
|
@@ -80,11 +80,13 @@ class ChatMessageTemplate {
|
|
|
80
80
|
content;
|
|
81
81
|
name;
|
|
82
82
|
options;
|
|
83
|
-
|
|
83
|
+
cacheControl;
|
|
84
|
+
constructor(role, content, name, options, cacheControl) {
|
|
84
85
|
this.role = role;
|
|
85
86
|
this.content = content;
|
|
86
87
|
this.name = name;
|
|
87
88
|
this.options = options;
|
|
89
|
+
this.cacheControl = cacheControl;
|
|
88
90
|
}
|
|
89
91
|
async format(variables, options) {
|
|
90
92
|
options = { ...this.options, ...(0, type_utils_js_1.omitBy)(options ?? {}, (v) => (0, type_utils_js_1.isNil)(v)) };
|
|
@@ -103,29 +105,30 @@ class ChatMessageTemplate {
|
|
|
103
105
|
role: this.role,
|
|
104
106
|
content,
|
|
105
107
|
name: this.name,
|
|
108
|
+
cacheControl: this.cacheControl,
|
|
106
109
|
};
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
exports.ChatMessageTemplate = ChatMessageTemplate;
|
|
110
113
|
class SystemMessageTemplate extends ChatMessageTemplate {
|
|
111
|
-
static from(content, name, options) {
|
|
112
|
-
return new SystemMessageTemplate("system", content, name, options);
|
|
114
|
+
static from(content, name, options, cacheControl) {
|
|
115
|
+
return new SystemMessageTemplate("system", content, name, options, cacheControl);
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
exports.SystemMessageTemplate = SystemMessageTemplate;
|
|
116
119
|
class UserMessageTemplate extends ChatMessageTemplate {
|
|
117
|
-
static from(template, name, options) {
|
|
118
|
-
return new UserMessageTemplate("user", template, name, options);
|
|
120
|
+
static from(template, name, options, cacheControl) {
|
|
121
|
+
return new UserMessageTemplate("user", template, name, options, cacheControl);
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
exports.UserMessageTemplate = UserMessageTemplate;
|
|
122
125
|
class AgentMessageTemplate extends ChatMessageTemplate {
|
|
123
126
|
toolCalls;
|
|
124
|
-
static from(template, toolCalls, name, options) {
|
|
125
|
-
return new AgentMessageTemplate(template, toolCalls, name, options);
|
|
127
|
+
static from(template, toolCalls, name, options, cacheControl) {
|
|
128
|
+
return new AgentMessageTemplate(template, toolCalls, name, options, cacheControl);
|
|
126
129
|
}
|
|
127
|
-
constructor(content, toolCalls, name, options) {
|
|
128
|
-
super("agent", content, name, options);
|
|
130
|
+
constructor(content, toolCalls, name, options, cacheControl) {
|
|
131
|
+
super("agent", content, name, options, cacheControl);
|
|
129
132
|
this.toolCalls = toolCalls;
|
|
130
133
|
}
|
|
131
134
|
async format(_variables, _options) {
|
|
@@ -135,17 +138,18 @@ class AgentMessageTemplate extends ChatMessageTemplate {
|
|
|
135
138
|
// NOTE: agent message should not rendered by template
|
|
136
139
|
content: this.content,
|
|
137
140
|
toolCalls: this.toolCalls,
|
|
141
|
+
cacheControl: this.cacheControl,
|
|
138
142
|
};
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
145
|
exports.AgentMessageTemplate = AgentMessageTemplate;
|
|
142
146
|
class ToolMessageTemplate extends ChatMessageTemplate {
|
|
143
147
|
toolCallId;
|
|
144
|
-
static from(content, toolCallId, name, options) {
|
|
145
|
-
return new ToolMessageTemplate(content, toolCallId, name, options);
|
|
148
|
+
static from(content, toolCallId, name, options, cacheControl) {
|
|
149
|
+
return new ToolMessageTemplate(content, toolCallId, name, options, cacheControl);
|
|
146
150
|
}
|
|
147
|
-
constructor(content, toolCallId, name, options) {
|
|
148
|
-
super("tool", typeof content === "string" ? content : (0, yaml_1.stringify)(content), name, options);
|
|
151
|
+
constructor(content, toolCallId, name, options, cacheControl) {
|
|
152
|
+
super("tool", typeof content === "string" ? content : (0, yaml_1.stringify)(content), name, options, cacheControl);
|
|
149
153
|
this.toolCallId = toolCallId;
|
|
150
154
|
}
|
|
151
155
|
async format(_variables, _options) {
|
|
@@ -155,6 +159,7 @@ class ToolMessageTemplate extends ChatMessageTemplate {
|
|
|
155
159
|
// NOTE: tool result should not rendered by template
|
|
156
160
|
content: this.content,
|
|
157
161
|
toolCallId: this.toolCallId,
|
|
162
|
+
cacheControl: this.cacheControl,
|
|
158
163
|
};
|
|
159
164
|
}
|
|
160
165
|
}
|
|
@@ -179,11 +184,23 @@ const systemChatMessageSchema = zod_1.z.object({
|
|
|
179
184
|
role: zod_1.z.literal("system"),
|
|
180
185
|
content: zod_1.z.string(),
|
|
181
186
|
name: zod_1.z.string().optional(),
|
|
187
|
+
cacheControl: zod_1.z
|
|
188
|
+
.object({
|
|
189
|
+
type: zod_1.z.literal("ephemeral"),
|
|
190
|
+
ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
|
|
191
|
+
})
|
|
192
|
+
.optional(),
|
|
182
193
|
});
|
|
183
194
|
const userChatMessageSchema = zod_1.z.object({
|
|
184
195
|
role: zod_1.z.literal("user"),
|
|
185
196
|
content: zod_1.z.string(),
|
|
186
197
|
name: zod_1.z.string().optional(),
|
|
198
|
+
cacheControl: zod_1.z
|
|
199
|
+
.object({
|
|
200
|
+
type: zod_1.z.literal("ephemeral"),
|
|
201
|
+
ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
|
|
202
|
+
})
|
|
203
|
+
.optional(),
|
|
187
204
|
});
|
|
188
205
|
const chatModelOutputToolCallSchema = zod_1.z.object({
|
|
189
206
|
id: zod_1.z.string(),
|
|
@@ -198,6 +215,12 @@ const agentChatMessageSchema = zod_1.z.object({
|
|
|
198
215
|
content: zod_1.z.string().optional(),
|
|
199
216
|
toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
|
|
200
217
|
name: zod_1.z.string().optional(),
|
|
218
|
+
cacheControl: zod_1.z
|
|
219
|
+
.object({
|
|
220
|
+
type: zod_1.z.literal("ephemeral"),
|
|
221
|
+
ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
|
|
222
|
+
})
|
|
223
|
+
.optional(),
|
|
201
224
|
});
|
|
202
225
|
const toolChatMessageSchema = zod_1.z.object({
|
|
203
226
|
role: zod_1.z.literal("tool"),
|
|
@@ -206,6 +229,12 @@ const toolChatMessageSchema = zod_1.z.object({
|
|
|
206
229
|
.transform((val) => (typeof val !== "string" ? JSON.stringify(val) : val)),
|
|
207
230
|
toolCallId: zod_1.z.string(),
|
|
208
231
|
name: zod_1.z.string().optional(),
|
|
232
|
+
cacheControl: zod_1.z
|
|
233
|
+
.object({
|
|
234
|
+
type: zod_1.z.literal("ephemeral"),
|
|
235
|
+
ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
|
|
236
|
+
})
|
|
237
|
+
.optional(),
|
|
209
238
|
});
|
|
210
239
|
const chatMessageSchema = zod_1.z.union([
|
|
211
240
|
systemChatMessageSchema,
|
|
@@ -224,13 +253,13 @@ function parseChatMessages(messages) {
|
|
|
224
253
|
return messages.map((message) => {
|
|
225
254
|
switch (message.role) {
|
|
226
255
|
case "system":
|
|
227
|
-
return SystemMessageTemplate.from(message.content, message.name, message.options);
|
|
256
|
+
return SystemMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
|
|
228
257
|
case "user":
|
|
229
|
-
return UserMessageTemplate.from(message.content, message.name, message.options);
|
|
258
|
+
return UserMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
|
|
230
259
|
case "agent":
|
|
231
|
-
return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options);
|
|
260
|
+
return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options, message.cacheControl);
|
|
232
261
|
case "tool":
|
|
233
|
-
return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options);
|
|
262
|
+
return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options, message.cacheControl);
|
|
234
263
|
}
|
|
235
264
|
});
|
|
236
265
|
}
|
|
@@ -203,6 +203,13 @@ export interface ChatModelInputMessage {
|
|
|
203
203
|
* Name of the message sender (for multi-agent scenarios)
|
|
204
204
|
*/
|
|
205
205
|
name?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Cache control marker for the entire message (only supported by Claude)
|
|
208
|
+
*
|
|
209
|
+
* This is syntactic sugar that applies cacheControl to the last content block
|
|
210
|
+
* of the message. See {@link CacheControl} for details.
|
|
211
|
+
*/
|
|
212
|
+
cacheControl?: CacheControl;
|
|
206
213
|
}
|
|
207
214
|
/**
|
|
208
215
|
* Type of input message content
|
|
@@ -218,27 +225,64 @@ export type ChatModelInputMessageContent = string | UnionContent[];
|
|
|
218
225
|
export type TextContent = {
|
|
219
226
|
type: "text";
|
|
220
227
|
text: string;
|
|
228
|
+
/**
|
|
229
|
+
* Cache control marker (only supported by Claude)
|
|
230
|
+
*
|
|
231
|
+
* When set, this content block will be marked as a cache breakpoint.
|
|
232
|
+
* See {@link CacheControl} for details.
|
|
233
|
+
*/
|
|
234
|
+
cacheControl?: CacheControl;
|
|
221
235
|
};
|
|
222
236
|
export declare const textContentSchema: z.ZodObject<{
|
|
223
237
|
type: z.ZodLiteral<"text">;
|
|
224
238
|
text: z.ZodString;
|
|
239
|
+
cacheControl: ZodType<{
|
|
240
|
+
type: "ephemeral";
|
|
241
|
+
ttl?: "5m" | "1h" | undefined;
|
|
242
|
+
} | undefined, z.ZodTypeDef, {
|
|
243
|
+
type: "ephemeral";
|
|
244
|
+
ttl?: "5m" | "1h" | undefined;
|
|
245
|
+
} | undefined>;
|
|
225
246
|
}, "strip", z.ZodTypeAny, {
|
|
226
247
|
type: "text";
|
|
227
248
|
text: string;
|
|
249
|
+
cacheControl?: {
|
|
250
|
+
type: "ephemeral";
|
|
251
|
+
ttl?: "5m" | "1h" | undefined;
|
|
252
|
+
} | undefined;
|
|
228
253
|
}, {
|
|
229
254
|
type: "text";
|
|
230
255
|
text: string;
|
|
256
|
+
cacheControl?: {
|
|
257
|
+
type: "ephemeral";
|
|
258
|
+
ttl?: "5m" | "1h" | undefined;
|
|
259
|
+
} | undefined;
|
|
231
260
|
}>;
|
|
232
261
|
export type UnionContent = TextContent | FileUnionContent;
|
|
233
262
|
export declare const unionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
234
263
|
type: z.ZodLiteral<"text">;
|
|
235
264
|
text: z.ZodString;
|
|
265
|
+
cacheControl: ZodType<{
|
|
266
|
+
type: "ephemeral";
|
|
267
|
+
ttl?: "5m" | "1h" | undefined;
|
|
268
|
+
} | undefined, z.ZodTypeDef, {
|
|
269
|
+
type: "ephemeral";
|
|
270
|
+
ttl?: "5m" | "1h" | undefined;
|
|
271
|
+
} | undefined>;
|
|
236
272
|
}, "strip", z.ZodTypeAny, {
|
|
237
273
|
type: "text";
|
|
238
274
|
text: string;
|
|
275
|
+
cacheControl?: {
|
|
276
|
+
type: "ephemeral";
|
|
277
|
+
ttl?: "5m" | "1h" | undefined;
|
|
278
|
+
} | undefined;
|
|
239
279
|
}, {
|
|
240
280
|
type: "text";
|
|
241
281
|
text: string;
|
|
282
|
+
cacheControl?: {
|
|
283
|
+
type: "ephemeral";
|
|
284
|
+
ttl?: "5m" | "1h" | undefined;
|
|
285
|
+
} | undefined;
|
|
242
286
|
}>, z.ZodObject<{
|
|
243
287
|
filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
244
288
|
mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
@@ -340,6 +384,14 @@ export interface ChatModelInputTool {
|
|
|
340
384
|
* For example, Gemini's thought_signature
|
|
341
385
|
*/
|
|
342
386
|
metadata?: Record<string, any>;
|
|
387
|
+
/**
|
|
388
|
+
* Cache control marker (only supported by Claude)
|
|
389
|
+
*
|
|
390
|
+
* When set, this tool definition will be marked as a cache breakpoint.
|
|
391
|
+
* Typically applied to the last tool in the tools array.
|
|
392
|
+
* See {@link CacheControl} for details.
|
|
393
|
+
*/
|
|
394
|
+
cacheControl?: CacheControl;
|
|
343
395
|
}
|
|
344
396
|
/**
|
|
345
397
|
* Tool selection strategy
|
|
@@ -362,6 +414,82 @@ export type ChatModelInputToolChoice = "auto" | "none" | "required" | {
|
|
|
362
414
|
};
|
|
363
415
|
};
|
|
364
416
|
export type Modality = "text" | "image" | "audio";
|
|
417
|
+
/**
|
|
418
|
+
* Cache control marker for prompt caching
|
|
419
|
+
*
|
|
420
|
+
* Used to mark content blocks, messages, or tools for caching.
|
|
421
|
+
* Currently only supported by Anthropic (Claude) models.
|
|
422
|
+
*/
|
|
423
|
+
export interface CacheControl {
|
|
424
|
+
/**
|
|
425
|
+
* Cache type (currently only "ephemeral" is supported)
|
|
426
|
+
*/
|
|
427
|
+
type: "ephemeral";
|
|
428
|
+
/**
|
|
429
|
+
* Cache TTL (Time To Live)
|
|
430
|
+
* - "5m": 5 minutes (default)
|
|
431
|
+
* - "1h": 1 hour
|
|
432
|
+
*/
|
|
433
|
+
ttl?: "5m" | "1h";
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Cache configuration options
|
|
437
|
+
*
|
|
438
|
+
* Controls how prompt caching is used for supported providers.
|
|
439
|
+
* Prompt caching can significantly reduce costs and latency by reusing
|
|
440
|
+
* previously processed prompts (system messages, tool definitions, etc.).
|
|
441
|
+
*/
|
|
442
|
+
export interface CacheConfig {
|
|
443
|
+
/**
|
|
444
|
+
* Whether to enable prompt caching
|
|
445
|
+
*
|
|
446
|
+
* - OpenAI: Ignored (always enabled automatically)
|
|
447
|
+
* - Gemini: Controls explicit caching
|
|
448
|
+
* - Claude: Controls whether to add cache_control markers
|
|
449
|
+
*
|
|
450
|
+
* @default true
|
|
451
|
+
*/
|
|
452
|
+
enabled?: boolean;
|
|
453
|
+
/**
|
|
454
|
+
* Cache TTL (Time To Live)
|
|
455
|
+
*
|
|
456
|
+
* - OpenAI: Ignored (automatic)
|
|
457
|
+
* - Gemini: Supports custom seconds
|
|
458
|
+
* - Claude: Only supports "5m" or "1h"
|
|
459
|
+
*
|
|
460
|
+
* @default "5m"
|
|
461
|
+
*/
|
|
462
|
+
ttl?: "5m" | "1h" | number;
|
|
463
|
+
/**
|
|
464
|
+
* Caching strategy
|
|
465
|
+
*
|
|
466
|
+
* - "auto": Automatically add cache breakpoints at optimal locations
|
|
467
|
+
* - "manual": Require explicit cacheControl markers on messages/tools
|
|
468
|
+
*
|
|
469
|
+
* @default "auto"
|
|
470
|
+
*/
|
|
471
|
+
strategy?: "auto" | "manual";
|
|
472
|
+
/**
|
|
473
|
+
* Auto cache breakpoint locations (only effective when strategy="auto")
|
|
474
|
+
*
|
|
475
|
+
* @default { tools: true, system: true, lastMessage: false }
|
|
476
|
+
*/
|
|
477
|
+
autoBreakpoints?: {
|
|
478
|
+
/** Cache tool definitions */
|
|
479
|
+
tools?: boolean;
|
|
480
|
+
/** Cache system messages */
|
|
481
|
+
system?: boolean;
|
|
482
|
+
/** Cache last message in conversation history */
|
|
483
|
+
lastMessage?: boolean;
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Default cache configuration
|
|
488
|
+
*
|
|
489
|
+
* Enables automatic caching for system messages and tool definitions,
|
|
490
|
+
* which typically provides the best cost/performance tradeoff.
|
|
491
|
+
*/
|
|
492
|
+
export declare const DEFAULT_CACHE_CONFIG: CacheConfig;
|
|
365
493
|
/**
|
|
366
494
|
* Model-specific configuration options
|
|
367
495
|
*
|
|
@@ -395,6 +523,15 @@ export interface ChatModelInputOptions extends Record<string, unknown> {
|
|
|
395
523
|
modalities?: Modality[];
|
|
396
524
|
preferInputFileType?: "file" | "url";
|
|
397
525
|
reasoningEffort?: number | "minimal" | "low" | "medium" | "high";
|
|
526
|
+
/**
|
|
527
|
+
* Cache configuration for prompt caching
|
|
528
|
+
*
|
|
529
|
+
* Enables caching of system messages, tool definitions, and conversation history
|
|
530
|
+
* to reduce costs and latency. See {@link CacheConfig} for details.
|
|
531
|
+
*
|
|
532
|
+
* @default DEFAULT_CACHE_CONFIG (enabled with auto strategy)
|
|
533
|
+
*/
|
|
534
|
+
cacheConfig?: CacheConfig;
|
|
398
535
|
}
|
|
399
536
|
export type ChatModelInputOptionsWithGetter = GetterSchema<ChatModelInputOptions>;
|
|
400
537
|
/**
|
|
@@ -492,6 +629,16 @@ export interface ChatModelOutputUsage {
|
|
|
492
629
|
* AIGNE Hub credit usage
|
|
493
630
|
*/
|
|
494
631
|
aigneHubCredits?: number;
|
|
632
|
+
/**
|
|
633
|
+
* Number of tokens written to cache (first time caching)
|
|
634
|
+
* Only applicable for providers that support explicit cache creation (e.g., Anthropic)
|
|
635
|
+
*/
|
|
636
|
+
cacheCreationInputTokens?: number;
|
|
637
|
+
/**
|
|
638
|
+
* Number of tokens read from cache (cache hit)
|
|
639
|
+
* Supported by OpenAI, Anthropic, and Gemini
|
|
640
|
+
*/
|
|
641
|
+
cacheReadInputTokens?: number;
|
|
495
642
|
/**
|
|
496
643
|
* Credit prefix
|
|
497
644
|
*/
|
|
@@ -501,15 +648,21 @@ export declare const chatModelOutputUsageSchema: z.ZodObject<{
|
|
|
501
648
|
inputTokens: z.ZodNumber;
|
|
502
649
|
outputTokens: z.ZodNumber;
|
|
503
650
|
aigneHubCredits: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
651
|
+
cacheCreationInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
652
|
+
cacheReadInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
504
653
|
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
505
654
|
}, "strip", z.ZodTypeAny, {
|
|
506
655
|
inputTokens: number;
|
|
507
656
|
outputTokens: number;
|
|
508
657
|
aigneHubCredits?: number | undefined;
|
|
658
|
+
cacheCreationInputTokens?: number | undefined;
|
|
659
|
+
cacheReadInputTokens?: number | undefined;
|
|
509
660
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
510
661
|
}, {
|
|
511
662
|
inputTokens: number;
|
|
512
663
|
outputTokens: number;
|
|
513
664
|
aigneHubCredits?: number | undefined;
|
|
665
|
+
cacheCreationInputTokens?: number | undefined;
|
|
666
|
+
cacheReadInputTokens?: number | undefined;
|
|
514
667
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
515
668
|
}>;
|
|
@@ -196,16 +196,22 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
196
196
|
inputTokens: z.ZodNumber;
|
|
197
197
|
outputTokens: z.ZodNumber;
|
|
198
198
|
aigneHubCredits: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
199
|
+
cacheCreationInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
200
|
+
cacheReadInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
199
201
|
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
200
202
|
}, "strip", z.ZodTypeAny, {
|
|
201
203
|
inputTokens: number;
|
|
202
204
|
outputTokens: number;
|
|
203
205
|
aigneHubCredits?: number | undefined;
|
|
206
|
+
cacheCreationInputTokens?: number | undefined;
|
|
207
|
+
cacheReadInputTokens?: number | undefined;
|
|
204
208
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
205
209
|
}, {
|
|
206
210
|
inputTokens: number;
|
|
207
211
|
outputTokens: number;
|
|
208
212
|
aigneHubCredits?: number | undefined;
|
|
213
|
+
cacheCreationInputTokens?: number | undefined;
|
|
214
|
+
cacheReadInputTokens?: number | undefined;
|
|
209
215
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
210
216
|
}>>;
|
|
211
217
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -231,6 +237,8 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
231
237
|
inputTokens: number;
|
|
232
238
|
outputTokens: number;
|
|
233
239
|
aigneHubCredits?: number | undefined;
|
|
240
|
+
cacheCreationInputTokens?: number | undefined;
|
|
241
|
+
cacheReadInputTokens?: number | undefined;
|
|
234
242
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
235
243
|
} | undefined;
|
|
236
244
|
}, {
|
|
@@ -255,6 +263,8 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
255
263
|
inputTokens: number;
|
|
256
264
|
outputTokens: number;
|
|
257
265
|
aigneHubCredits?: number | undefined;
|
|
266
|
+
cacheCreationInputTokens?: number | undefined;
|
|
267
|
+
cacheReadInputTokens?: number | undefined;
|
|
258
268
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
259
269
|
} | undefined;
|
|
260
270
|
}>;
|
|
@@ -203,16 +203,22 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
203
203
|
inputTokens: z.ZodNumber;
|
|
204
204
|
outputTokens: z.ZodNumber;
|
|
205
205
|
aigneHubCredits: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
206
|
+
cacheCreationInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
207
|
+
cacheReadInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
206
208
|
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
207
209
|
}, "strip", z.ZodTypeAny, {
|
|
208
210
|
inputTokens: number;
|
|
209
211
|
outputTokens: number;
|
|
210
212
|
aigneHubCredits?: number | undefined;
|
|
213
|
+
cacheCreationInputTokens?: number | undefined;
|
|
214
|
+
cacheReadInputTokens?: number | undefined;
|
|
211
215
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
212
216
|
}, {
|
|
213
217
|
inputTokens: number;
|
|
214
218
|
outputTokens: number;
|
|
215
219
|
aigneHubCredits?: number | undefined;
|
|
220
|
+
cacheCreationInputTokens?: number | undefined;
|
|
221
|
+
cacheReadInputTokens?: number | undefined;
|
|
216
222
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
217
223
|
}>>;
|
|
218
224
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -239,6 +245,8 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
239
245
|
inputTokens: number;
|
|
240
246
|
outputTokens: number;
|
|
241
247
|
aigneHubCredits?: number | undefined;
|
|
248
|
+
cacheCreationInputTokens?: number | undefined;
|
|
249
|
+
cacheReadInputTokens?: number | undefined;
|
|
242
250
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
243
251
|
} | undefined;
|
|
244
252
|
seconds?: number | undefined;
|
|
@@ -264,6 +272,8 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
264
272
|
inputTokens: number;
|
|
265
273
|
outputTokens: number;
|
|
266
274
|
aigneHubCredits?: number | undefined;
|
|
275
|
+
cacheCreationInputTokens?: number | undefined;
|
|
276
|
+
cacheReadInputTokens?: number | undefined;
|
|
267
277
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
268
278
|
} | undefined;
|
|
269
279
|
seconds?: number | undefined;
|
package/lib/dts/aigne/usage.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface ContextUsage {
|
|
|
8
8
|
creditPrefix?: "$" | "€" | "¥";
|
|
9
9
|
agentCalls: number;
|
|
10
10
|
duration: number;
|
|
11
|
+
/** Number of tokens written to cache (first time caching) */
|
|
12
|
+
cacheCreationInputTokens: number;
|
|
13
|
+
/** Number of tokens read from cache (cache hit) */
|
|
14
|
+
cacheReadInputTokens: number;
|
|
11
15
|
}
|
|
12
16
|
/**
|
|
13
17
|
* @hidden
|