@aigne/core 1.72.0-beta.2 → 1.72.0-beta.4
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 +34 -0
- package/lib/cjs/agents/agent.d.ts +31 -1
- package/lib/cjs/agents/agent.js +13 -0
- package/lib/cjs/agents/ai-agent.d.ts +7 -0
- package/lib/cjs/agents/ai-agent.js +85 -3
- package/lib/cjs/agents/chat-model.d.ts +153 -0
- package/lib/cjs/agents/chat-model.js +35 -1
- package/lib/cjs/agents/image-agent.d.ts +17 -1
- package/lib/cjs/agents/image-agent.js +16 -0
- package/lib/cjs/agents/image-model.d.ts +14 -4
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- package/lib/cjs/agents/team-agent.d.ts +55 -0
- package/lib/cjs/agents/team-agent.js +31 -0
- package/lib/cjs/agents/transform-agent.d.ts +12 -0
- package/lib/cjs/agents/transform-agent.js +13 -0
- package/lib/cjs/agents/video-model.d.ts +14 -4
- 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 +5 -63
- package/lib/cjs/loader/agent-yaml.js +4 -129
- package/lib/cjs/loader/agents.d.ts +4 -0
- package/lib/cjs/loader/agents.js +17 -0
- package/lib/cjs/loader/index.d.ts +18 -14
- package/lib/cjs/loader/index.js +20 -81
- package/lib/cjs/loader/schema.d.ts +21 -6
- package/lib/cjs/loader/schema.js +60 -1
- package/lib/cjs/prompt/prompt-builder.js +0 -1
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
- package/lib/cjs/prompt/skills/afs/delete.js +15 -3
- package/lib/cjs/prompt/skills/afs/edit.js +30 -7
- package/lib/cjs/prompt/skills/afs/exec.js +17 -6
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.js +26 -10
- package/lib/cjs/prompt/skills/afs/read.js +14 -3
- package/lib/cjs/prompt/skills/afs/rename.js +18 -4
- package/lib/cjs/prompt/skills/afs/search.js +21 -5
- package/lib/cjs/prompt/skills/afs/write.js +18 -4
- package/lib/cjs/prompt/template.d.ts +92 -17
- package/lib/cjs/prompt/template.js +46 -17
- package/lib/dts/agents/agent.d.ts +31 -1
- package/lib/dts/agents/ai-agent.d.ts +7 -0
- package/lib/dts/agents/chat-model.d.ts +153 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +14 -4
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- package/lib/dts/agents/team-agent.d.ts +55 -0
- package/lib/dts/agents/transform-agent.d.ts +12 -0
- package/lib/dts/agents/video-model.d.ts +14 -4
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/aigne/usage.d.ts +4 -0
- package/lib/dts/loader/agent-yaml.d.ts +5 -63
- package/lib/dts/loader/agents.d.ts +4 -0
- package/lib/dts/loader/index.d.ts +18 -14
- package/lib/dts/loader/schema.d.ts +21 -6
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/dts/prompt/template.d.ts +92 -17
- package/lib/esm/agents/agent.d.ts +31 -1
- package/lib/esm/agents/agent.js +13 -0
- package/lib/esm/agents/ai-agent.d.ts +7 -0
- package/lib/esm/agents/ai-agent.js +85 -3
- package/lib/esm/agents/chat-model.d.ts +153 -0
- package/lib/esm/agents/chat-model.js +34 -0
- package/lib/esm/agents/image-agent.d.ts +17 -1
- package/lib/esm/agents/image-agent.js +16 -0
- package/lib/esm/agents/image-model.d.ts +14 -4
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- package/lib/esm/agents/team-agent.d.ts +55 -0
- package/lib/esm/agents/team-agent.js +31 -0
- package/lib/esm/agents/transform-agent.d.ts +12 -0
- package/lib/esm/agents/transform-agent.js +13 -0
- package/lib/esm/agents/video-model.d.ts +14 -4
- package/lib/esm/aigne/context.d.ts +2 -2
- 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 +5 -63
- package/lib/esm/loader/agent-yaml.js +4 -128
- package/lib/esm/loader/agents.d.ts +4 -0
- package/lib/esm/loader/agents.js +14 -0
- package/lib/esm/loader/index.d.ts +18 -14
- package/lib/esm/loader/index.js +21 -81
- package/lib/esm/loader/schema.d.ts +21 -6
- package/lib/esm/loader/schema.js +57 -0
- package/lib/esm/prompt/prompt-builder.js +1 -2
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
- package/lib/esm/prompt/skills/afs/delete.js +15 -3
- package/lib/esm/prompt/skills/afs/edit.js +30 -7
- package/lib/esm/prompt/skills/afs/exec.js +17 -6
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.js +26 -10
- package/lib/esm/prompt/skills/afs/read.js +14 -3
- package/lib/esm/prompt/skills/afs/rename.js +18 -4
- package/lib/esm/prompt/skills/afs/search.js +21 -5
- package/lib/esm/prompt/skills/afs/write.js +18 -4
- package/lib/esm/prompt/template.d.ts +92 -17
- package/lib/esm/prompt/template.js +46 -17
- package/package.json +5 -4
|
@@ -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
|
}>;
|
|
@@ -188,6 +188,10 @@ export class ChatModel extends Model {
|
|
|
188
188
|
options.context.usage.inputTokens += usage.inputTokens;
|
|
189
189
|
if (usage.aigneHubCredits)
|
|
190
190
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
191
|
+
if (usage.cacheCreationInputTokens)
|
|
192
|
+
options.context.usage.cacheCreationInputTokens += usage.cacheCreationInputTokens;
|
|
193
|
+
if (usage.cacheReadInputTokens)
|
|
194
|
+
options.context.usage.cacheReadInputTokens += usage.cacheReadInputTokens;
|
|
191
195
|
if (usage.creditPrefix)
|
|
192
196
|
options.context.usage.creditPrefix = usage.creditPrefix;
|
|
193
197
|
}
|
|
@@ -244,6 +248,10 @@ export const roleSchema = z.union([
|
|
|
244
248
|
export const textContentSchema = z.object({
|
|
245
249
|
type: z.literal("text"),
|
|
246
250
|
text: z.string(),
|
|
251
|
+
cacheControl: optionalize(z.object({
|
|
252
|
+
type: z.literal("ephemeral"),
|
|
253
|
+
ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
|
|
254
|
+
})),
|
|
247
255
|
});
|
|
248
256
|
export const unionContentSchema = z.discriminatedUnion("type", [
|
|
249
257
|
textContentSchema,
|
|
@@ -265,6 +273,10 @@ const chatModelInputMessageSchema = z.object({
|
|
|
265
273
|
}))),
|
|
266
274
|
toolCallId: optionalize(z.string()),
|
|
267
275
|
name: optionalize(z.string()),
|
|
276
|
+
cacheControl: optionalize(z.object({
|
|
277
|
+
type: z.literal("ephemeral"),
|
|
278
|
+
ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
|
|
279
|
+
})),
|
|
268
280
|
});
|
|
269
281
|
const chatModelInputResponseFormatSchema = z.discriminatedUnion("type", [
|
|
270
282
|
z.object({ type: z.literal("text") }),
|
|
@@ -286,6 +298,10 @@ const chatModelInputToolSchema = z.object({
|
|
|
286
298
|
parameters: z.record(z.string(), z.unknown()),
|
|
287
299
|
}),
|
|
288
300
|
metadata: optionalize(z.record(z.string(), z.unknown())),
|
|
301
|
+
cacheControl: optionalize(z.object({
|
|
302
|
+
type: z.literal("ephemeral"),
|
|
303
|
+
ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
|
|
304
|
+
})),
|
|
289
305
|
});
|
|
290
306
|
const chatModelInputToolChoiceSchema = z.union([
|
|
291
307
|
z.literal("auto"),
|
|
@@ -293,6 +309,22 @@ const chatModelInputToolChoiceSchema = z.union([
|
|
|
293
309
|
z.literal("required"),
|
|
294
310
|
chatModelInputToolSchema,
|
|
295
311
|
]);
|
|
312
|
+
/**
|
|
313
|
+
* Default cache configuration
|
|
314
|
+
*
|
|
315
|
+
* Enables automatic caching for system messages and tool definitions,
|
|
316
|
+
* which typically provides the best cost/performance tradeoff.
|
|
317
|
+
*/
|
|
318
|
+
export const DEFAULT_CACHE_CONFIG = {
|
|
319
|
+
enabled: true,
|
|
320
|
+
ttl: "5m",
|
|
321
|
+
strategy: "auto",
|
|
322
|
+
autoBreakpoints: {
|
|
323
|
+
tools: true,
|
|
324
|
+
system: true,
|
|
325
|
+
lastMessage: false,
|
|
326
|
+
},
|
|
327
|
+
};
|
|
296
328
|
const modelOptionsSchemaProperties = {
|
|
297
329
|
model: z.string(),
|
|
298
330
|
temperature: z.number(),
|
|
@@ -341,6 +373,8 @@ export const chatModelOutputUsageSchema = z.object({
|
|
|
341
373
|
inputTokens: z.number(),
|
|
342
374
|
outputTokens: z.number(),
|
|
343
375
|
aigneHubCredits: optionalize(z.number()),
|
|
376
|
+
cacheCreationInputTokens: optionalize(z.number()),
|
|
377
|
+
cacheReadInputTokens: optionalize(z.number()),
|
|
344
378
|
creditPrefix: optionalize(z.union([z.literal("$"), z.literal("€"), z.literal("¥")])),
|
|
345
379
|
});
|
|
346
380
|
const chatModelOutputSchema = z.object({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ZodObject, type ZodType } from "zod";
|
|
1
|
+
import z, { type ZodObject, type ZodType } from "zod";
|
|
2
2
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
|
|
4
4
|
import { type ImageModelOutput } from "./image-model.js";
|
|
@@ -13,6 +13,22 @@ export declare const imageAgentOptionsSchema: ZodObject<{
|
|
|
13
13
|
}>;
|
|
14
14
|
export declare class ImageAgent<I extends Message = any, O extends ImageModelOutput = any> extends Agent<I, O> {
|
|
15
15
|
tag: string;
|
|
16
|
+
static schema({ filepath }: {
|
|
17
|
+
filepath: string;
|
|
18
|
+
}): z.ZodObject<{
|
|
19
|
+
instructions: z.ZodType<import("../loader/schema.js").Instructions, z.ZodTypeDef, import("../loader/schema.js").Instructions>;
|
|
20
|
+
inputFileKey: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
instructions: import("../loader/schema.js").Instructions;
|
|
23
|
+
inputFileKey?: string | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
instructions: import("../loader/schema.js").Instructions;
|
|
26
|
+
inputFileKey?: string | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
29
|
+
filepath: string;
|
|
30
|
+
parsed: object;
|
|
31
|
+
}): Promise<Agent<I, O>>;
|
|
16
32
|
static from<I extends Message = any, O extends ImageModelOutput = any>(options: ImageAgentOptions<I, O>): ImageAgent<I, O>;
|
|
17
33
|
constructor(options: ImageAgentOptions<I, O>);
|
|
18
34
|
instructions: PromptBuilder;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
+
import { camelizeSchema, getInstructionsSchema, instructionsToPromptBuilder, optionalize, } from "../loader/schema.js";
|
|
2
3
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
4
|
import { checkArguments } from "../utils/type-utils.js";
|
|
4
5
|
import { Agent, agentOptionsSchema, } from "./agent.js";
|
|
@@ -10,6 +11,21 @@ export const imageAgentOptionsSchema = agentOptionsSchema.extend({
|
|
|
10
11
|
});
|
|
11
12
|
export class ImageAgent extends Agent {
|
|
12
13
|
tag = "ImageAgent";
|
|
14
|
+
static schema({ filepath }) {
|
|
15
|
+
const instructionsSchema = getInstructionsSchema({ filepath });
|
|
16
|
+
return camelizeSchema(z.object({
|
|
17
|
+
instructions: instructionsSchema,
|
|
18
|
+
inputFileKey: optionalize(z.string()),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
static async load(options) {
|
|
22
|
+
const valid = await ImageAgent.schema({ filepath: options.filepath }).parseAsync(options.parsed);
|
|
23
|
+
return new ImageAgent({
|
|
24
|
+
...options.parsed,
|
|
25
|
+
...valid,
|
|
26
|
+
instructions: instructionsToPromptBuilder(valid.instructions),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
13
29
|
static from(options) {
|
|
14
30
|
return new ImageAgent(options);
|
|
15
31
|
}
|
|
@@ -91,6 +91,7 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
91
91
|
}, "strip", z.ZodTypeAny, {
|
|
92
92
|
prompt: string;
|
|
93
93
|
modelOptions?: Record<string, unknown> | undefined;
|
|
94
|
+
outputFileType?: "local" | "url" | "file" | undefined;
|
|
94
95
|
image?: ({
|
|
95
96
|
type: "url";
|
|
96
97
|
url: string;
|
|
@@ -107,11 +108,11 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
107
108
|
filename?: string | undefined;
|
|
108
109
|
mimeType?: string | undefined;
|
|
109
110
|
})[] | undefined;
|
|
110
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
111
111
|
n?: number | undefined;
|
|
112
112
|
}, {
|
|
113
113
|
prompt: string;
|
|
114
114
|
modelOptions?: Record<string, unknown> | undefined;
|
|
115
|
+
outputFileType?: "local" | "url" | "file" | undefined;
|
|
115
116
|
image?: ({
|
|
116
117
|
type: "url";
|
|
117
118
|
url: string;
|
|
@@ -128,7 +129,6 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
128
129
|
filename?: string | undefined;
|
|
129
130
|
mimeType?: string | undefined;
|
|
130
131
|
})[] | undefined;
|
|
131
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
132
132
|
n?: number | undefined;
|
|
133
133
|
}>;
|
|
134
134
|
export interface ImageModelOutput extends Message {
|
|
@@ -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>;
|
|
@@ -226,13 +232,15 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
226
232
|
filename?: string | undefined;
|
|
227
233
|
mimeType?: string | undefined;
|
|
228
234
|
})[];
|
|
229
|
-
model?: string | undefined;
|
|
230
235
|
usage?: {
|
|
231
236
|
inputTokens: number;
|
|
232
237
|
outputTokens: number;
|
|
233
238
|
aigneHubCredits?: number | undefined;
|
|
239
|
+
cacheCreationInputTokens?: number | undefined;
|
|
240
|
+
cacheReadInputTokens?: number | undefined;
|
|
234
241
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
235
242
|
} | undefined;
|
|
243
|
+
model?: string | undefined;
|
|
236
244
|
}, {
|
|
237
245
|
images: ({
|
|
238
246
|
type: "url";
|
|
@@ -250,11 +258,13 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
250
258
|
filename?: string | undefined;
|
|
251
259
|
mimeType?: string | undefined;
|
|
252
260
|
})[];
|
|
253
|
-
model?: string | undefined;
|
|
254
261
|
usage?: {
|
|
255
262
|
inputTokens: number;
|
|
256
263
|
outputTokens: number;
|
|
257
264
|
aigneHubCredits?: number | undefined;
|
|
265
|
+
cacheCreationInputTokens?: number | undefined;
|
|
266
|
+
cacheReadInputTokens?: number | undefined;
|
|
258
267
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
259
268
|
} | undefined;
|
|
269
|
+
model?: string | undefined;
|
|
260
270
|
}>;
|
|
@@ -58,6 +58,23 @@ export type SSEServerParameters = {
|
|
|
58
58
|
*/
|
|
59
59
|
export declare class MCPAgent extends Agent {
|
|
60
60
|
tag: string;
|
|
61
|
+
static schema(): z.ZodObject<{
|
|
62
|
+
url: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
63
|
+
command: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
64
|
+
args: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
url?: string | undefined;
|
|
67
|
+
args?: string[] | undefined;
|
|
68
|
+
command?: string | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
url?: string | undefined;
|
|
71
|
+
args?: string[] | undefined;
|
|
72
|
+
command?: string | undefined;
|
|
73
|
+
}>;
|
|
74
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
75
|
+
filepath: string;
|
|
76
|
+
parsed: object;
|
|
77
|
+
}): Promise<Agent<I, O>>;
|
|
61
78
|
/**
|
|
62
79
|
* Create an MCPAgent from a connection to an SSE server.
|
|
63
80
|
*
|
|
@@ -5,6 +5,7 @@ import { SSEClientTransport, } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
|
5
5
|
import { StreamableHTTPClientTransport, } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
6
6
|
import { UriTemplate } from "@modelcontextprotocol/sdk/shared/uriTemplate.js";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { optionalize } from "../loader/schema.js";
|
|
8
9
|
import { logger } from "../utils/logger.js";
|
|
9
10
|
import { promptFromMCPPrompt, resourceFromMCPResource, toolFromMCPTool, } from "../utils/mcp-utils.js";
|
|
10
11
|
import { checkArguments, createAccessorArray } from "../utils/type-utils.js";
|
|
@@ -49,6 +50,23 @@ function getMCPServerString(options) {
|
|
|
49
50
|
*/
|
|
50
51
|
export class MCPAgent extends Agent {
|
|
51
52
|
tag = "MCPAgent";
|
|
53
|
+
static schema() {
|
|
54
|
+
return z.object({
|
|
55
|
+
url: optionalize(z.string()),
|
|
56
|
+
command: optionalize(z.string()),
|
|
57
|
+
args: optionalize(z.array(z.string())),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static async load(options) {
|
|
61
|
+
const valid = await MCPAgent.schema().parseAsync(options.parsed);
|
|
62
|
+
if (!valid.url && !valid.command) {
|
|
63
|
+
throw new Error(`Missing url or command in mcp agent: ${options.filepath}`);
|
|
64
|
+
}
|
|
65
|
+
return MCPAgent.from({
|
|
66
|
+
...options.parsed,
|
|
67
|
+
...valid,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
52
70
|
static from(options) {
|
|
53
71
|
checkArguments("MCPAgent.from", mcpAgentOptionsSchema, options);
|
|
54
72
|
if (isSSEServerParameters(options)) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AgentLoadOptions } from "../loader/index.js";
|
|
1
3
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
2
4
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
3
5
|
/**
|
|
@@ -200,6 +202,59 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
200
202
|
*/
|
|
201
203
|
export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
|
|
202
204
|
tag: string;
|
|
205
|
+
static schema({ filepath }: {
|
|
206
|
+
filepath: string;
|
|
207
|
+
}): z.ZodObject<{
|
|
208
|
+
mode: z.ZodType<ProcessMode | undefined, z.ZodTypeDef, ProcessMode | undefined>;
|
|
209
|
+
iterateOn: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
210
|
+
concurrency: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
211
|
+
iterateWithPreviousOutput: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
|
|
212
|
+
includeAllStepsOutput: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
|
|
213
|
+
reflection: z.ZodType<{
|
|
214
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
215
|
+
isApproved: string;
|
|
216
|
+
maxIterations?: number | undefined;
|
|
217
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
218
|
+
customErrorMessage?: string | undefined;
|
|
219
|
+
} | undefined, z.ZodTypeDef, {
|
|
220
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
221
|
+
isApproved: string;
|
|
222
|
+
maxIterations?: number | undefined;
|
|
223
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
224
|
+
customErrorMessage?: string | undefined;
|
|
225
|
+
} | undefined>;
|
|
226
|
+
}, "strip", z.ZodTypeAny, {
|
|
227
|
+
mode?: ProcessMode | undefined;
|
|
228
|
+
reflection?: {
|
|
229
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
230
|
+
isApproved: string;
|
|
231
|
+
maxIterations?: number | undefined;
|
|
232
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
233
|
+
customErrorMessage?: string | undefined;
|
|
234
|
+
} | undefined;
|
|
235
|
+
iterateOn?: string | undefined;
|
|
236
|
+
concurrency?: number | undefined;
|
|
237
|
+
iterateWithPreviousOutput?: boolean | undefined;
|
|
238
|
+
includeAllStepsOutput?: boolean | undefined;
|
|
239
|
+
}, {
|
|
240
|
+
mode?: ProcessMode | undefined;
|
|
241
|
+
reflection?: {
|
|
242
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
243
|
+
isApproved: string;
|
|
244
|
+
maxIterations?: number | undefined;
|
|
245
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
246
|
+
customErrorMessage?: string | undefined;
|
|
247
|
+
} | undefined;
|
|
248
|
+
iterateOn?: string | undefined;
|
|
249
|
+
concurrency?: number | undefined;
|
|
250
|
+
iterateWithPreviousOutput?: boolean | undefined;
|
|
251
|
+
includeAllStepsOutput?: boolean | undefined;
|
|
252
|
+
}>;
|
|
253
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
254
|
+
filepath: string;
|
|
255
|
+
parsed: object;
|
|
256
|
+
options: AgentLoadOptions;
|
|
257
|
+
}): Promise<Agent<I, O>>;
|
|
203
258
|
/**
|
|
204
259
|
* Create a TeamAgent from the provided options.
|
|
205
260
|
*
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { produce } from "immer";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { getNestAgentSchema } from "../loader/agent-yaml.js";
|
|
5
|
+
import { camelizeSchema, optionalize } from "../loader/schema.js";
|
|
3
6
|
import * as fastq from "../utils/queue.js";
|
|
4
7
|
import { mergeAgentResponseChunk } from "../utils/stream-utils.js";
|
|
5
8
|
import { isEmpty, isNil, isRecord, omit } from "../utils/type-utils.js";
|
|
@@ -47,6 +50,34 @@ export const DEFAULT_REFLECTION_MAX_ITERATIONS = 3;
|
|
|
47
50
|
*/
|
|
48
51
|
export class TeamAgent extends Agent {
|
|
49
52
|
tag = "TeamAgent";
|
|
53
|
+
static schema({ filepath }) {
|
|
54
|
+
const nestAgentSchema = getNestAgentSchema({ filepath });
|
|
55
|
+
return z.object({
|
|
56
|
+
mode: optionalize(z.nativeEnum(ProcessMode)),
|
|
57
|
+
iterateOn: optionalize(z.string()),
|
|
58
|
+
concurrency: optionalize(z.number().int().min(1)),
|
|
59
|
+
iterateWithPreviousOutput: optionalize(z.boolean()),
|
|
60
|
+
includeAllStepsOutput: optionalize(z.boolean()),
|
|
61
|
+
reflection: camelizeSchema(optionalize(z.object({
|
|
62
|
+
reviewer: nestAgentSchema,
|
|
63
|
+
isApproved: z.string(),
|
|
64
|
+
maxIterations: optionalize(z.number().int().min(1)),
|
|
65
|
+
returnLastOnMaxIterations: optionalize(z.boolean()),
|
|
66
|
+
customErrorMessage: optionalize(z.string()),
|
|
67
|
+
}))),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
static async load(options) {
|
|
71
|
+
const valid = await TeamAgent.schema({ filepath: options.filepath }).parseAsync(options.parsed);
|
|
72
|
+
return TeamAgent.from({
|
|
73
|
+
...options.parsed,
|
|
74
|
+
...valid,
|
|
75
|
+
reflection: valid.reflection && {
|
|
76
|
+
...valid.reflection,
|
|
77
|
+
reviewer: await options.options.loadNestAgent(options.filepath, valid.reflection.reviewer, options.options),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
50
81
|
/**
|
|
51
82
|
* Create a TeamAgent from the provided options.
|
|
52
83
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
2
3
|
/**
|
|
3
4
|
* Configuration options for TransformAgent
|
|
@@ -47,6 +48,17 @@ export interface TransformAgentOptions<I extends Message, O extends Message> ext
|
|
|
47
48
|
*/
|
|
48
49
|
export declare class TransformAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
49
50
|
static type: string;
|
|
51
|
+
static schema(): z.ZodObject<{
|
|
52
|
+
jsonata: z.ZodString;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
jsonata: string;
|
|
55
|
+
}, {
|
|
56
|
+
jsonata: string;
|
|
57
|
+
}>;
|
|
58
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
59
|
+
filepath: string;
|
|
60
|
+
parsed: object;
|
|
61
|
+
}): Promise<Agent<I, O>>;
|
|
50
62
|
/**
|
|
51
63
|
* Factory method to create a new TransformAgent instance
|
|
52
64
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import jsonata from "jsonata";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { Agent } from "./agent.js";
|
|
3
4
|
/**
|
|
4
5
|
* TransformAgent - A specialized agent for data transformation using JSONata expressions
|
|
@@ -17,6 +18,18 @@ import { Agent } from "./agent.js";
|
|
|
17
18
|
*/
|
|
18
19
|
export class TransformAgent extends Agent {
|
|
19
20
|
static type = "TransformAgent";
|
|
21
|
+
static schema() {
|
|
22
|
+
return z.object({
|
|
23
|
+
jsonata: z.string(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static async load(options) {
|
|
27
|
+
const parsed = await TransformAgent.schema().parseAsync(options.parsed);
|
|
28
|
+
return TransformAgent.from({
|
|
29
|
+
...options.parsed,
|
|
30
|
+
...parsed,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
20
33
|
/**
|
|
21
34
|
* Factory method to create a new TransformAgent instance
|
|
22
35
|
*
|