@aigne/core 1.71.0 → 1.72.0-beta.2
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 +49 -0
- package/lib/cjs/agents/agent.d.ts +5 -18
- package/lib/cjs/agents/agent.js +3 -3
- package/lib/cjs/agents/chat-model.d.ts +7 -0
- package/lib/cjs/agents/chat-model.js +3 -0
- package/lib/cjs/agents/image-model.d.ts +5 -0
- package/lib/cjs/agents/image-model.js +2 -0
- package/lib/cjs/agents/video-model.d.ts +5 -0
- package/lib/cjs/agents/video-model.js +2 -0
- package/lib/cjs/aigne/usage.d.ts +1 -0
- package/lib/cjs/loader/agent-yaml.d.ts +22 -1
- package/lib/cjs/loader/agent-yaml.js +18 -0
- package/lib/cjs/loader/index.js +26 -1
- package/lib/cjs/prompt/context/afs/history.d.ts +5 -0
- package/lib/cjs/prompt/context/afs/history.js +32 -0
- package/lib/cjs/prompt/context/afs/index.d.ts +20 -0
- package/lib/cjs/prompt/context/afs/index.js +47 -0
- package/lib/cjs/prompt/context/index.d.ts +31 -0
- package/lib/cjs/prompt/context/index.js +18 -0
- package/lib/cjs/prompt/prompt-builder.js +10 -39
- package/lib/cjs/prompt/skills/afs/base.d.ts +4 -0
- package/lib/cjs/prompt/skills/afs/base.js +8 -0
- package/lib/cjs/prompt/skills/afs/delete.d.ts +3 -2
- package/lib/cjs/prompt/skills/afs/delete.js +2 -2
- package/lib/cjs/prompt/skills/afs/edit.d.ts +4 -3
- package/lib/cjs/prompt/skills/afs/edit.js +6 -6
- package/lib/cjs/prompt/skills/afs/exec.d.ts +4 -3
- package/lib/cjs/prompt/skills/afs/exec.js +11 -6
- package/lib/cjs/prompt/skills/afs/list.d.ts +4 -4
- package/lib/cjs/prompt/skills/afs/list.js +19 -52
- package/lib/cjs/prompt/skills/afs/read.d.ts +4 -3
- package/lib/cjs/prompt/skills/afs/read.js +6 -6
- package/lib/cjs/prompt/skills/afs/rename.d.ts +3 -2
- package/lib/cjs/prompt/skills/afs/rename.js +2 -2
- package/lib/cjs/prompt/skills/afs/search.d.ts +4 -3
- package/lib/cjs/prompt/skills/afs/search.js +3 -3
- package/lib/cjs/prompt/skills/afs/write.d.ts +3 -2
- package/lib/cjs/prompt/skills/afs/write.js +2 -2
- package/lib/dts/agents/agent.d.ts +5 -18
- package/lib/dts/agents/chat-model.d.ts +7 -0
- package/lib/dts/agents/image-model.d.ts +5 -0
- package/lib/dts/agents/video-model.d.ts +5 -0
- package/lib/dts/aigne/usage.d.ts +1 -0
- package/lib/dts/loader/agent-yaml.d.ts +22 -1
- package/lib/dts/prompt/context/afs/history.d.ts +5 -0
- package/lib/dts/prompt/context/afs/index.d.ts +20 -0
- package/lib/dts/prompt/context/index.d.ts +31 -0
- package/lib/dts/prompt/skills/afs/base.d.ts +4 -0
- package/lib/dts/prompt/skills/afs/delete.d.ts +3 -2
- package/lib/dts/prompt/skills/afs/edit.d.ts +4 -3
- package/lib/dts/prompt/skills/afs/exec.d.ts +4 -3
- package/lib/dts/prompt/skills/afs/list.d.ts +4 -4
- package/lib/dts/prompt/skills/afs/read.d.ts +4 -3
- package/lib/dts/prompt/skills/afs/rename.d.ts +3 -2
- package/lib/dts/prompt/skills/afs/search.d.ts +4 -3
- package/lib/dts/prompt/skills/afs/write.d.ts +3 -2
- package/lib/esm/agents/agent.d.ts +5 -18
- package/lib/esm/agents/agent.js +3 -3
- package/lib/esm/agents/chat-model.d.ts +7 -0
- package/lib/esm/agents/chat-model.js +3 -0
- package/lib/esm/agents/image-model.d.ts +5 -0
- package/lib/esm/agents/image-model.js +2 -0
- package/lib/esm/agents/video-model.d.ts +5 -0
- package/lib/esm/agents/video-model.js +2 -0
- package/lib/esm/aigne/usage.d.ts +1 -0
- package/lib/esm/loader/agent-yaml.d.ts +22 -1
- package/lib/esm/loader/agent-yaml.js +18 -0
- package/lib/esm/loader/index.js +26 -1
- package/lib/esm/prompt/context/afs/history.d.ts +5 -0
- package/lib/esm/prompt/context/afs/history.js +29 -0
- package/lib/esm/prompt/context/afs/index.d.ts +20 -0
- package/lib/esm/prompt/context/afs/index.js +44 -0
- package/lib/esm/prompt/context/index.d.ts +31 -0
- package/lib/esm/prompt/context/index.js +15 -0
- package/lib/esm/prompt/prompt-builder.js +10 -39
- package/lib/esm/prompt/skills/afs/base.d.ts +4 -0
- package/lib/esm/prompt/skills/afs/base.js +4 -0
- package/lib/esm/prompt/skills/afs/delete.d.ts +3 -2
- package/lib/esm/prompt/skills/afs/delete.js +2 -2
- package/lib/esm/prompt/skills/afs/edit.d.ts +4 -3
- package/lib/esm/prompt/skills/afs/edit.js +6 -6
- package/lib/esm/prompt/skills/afs/exec.d.ts +4 -3
- package/lib/esm/prompt/skills/afs/exec.js +11 -6
- package/lib/esm/prompt/skills/afs/list.d.ts +4 -4
- package/lib/esm/prompt/skills/afs/list.js +19 -52
- package/lib/esm/prompt/skills/afs/read.d.ts +4 -3
- package/lib/esm/prompt/skills/afs/read.js +6 -6
- package/lib/esm/prompt/skills/afs/rename.d.ts +3 -2
- package/lib/esm/prompt/skills/afs/rename.js +2 -2
- package/lib/esm/prompt/skills/afs/search.d.ts +4 -3
- package/lib/esm/prompt/skills/afs/search.js +3 -3
- package/lib/esm/prompt/skills/afs/write.d.ts +3 -2
- package/lib/esm/prompt/skills/afs/write.js +2 -2
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.72.0-beta.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.1...core-v1.72.0-beta.2) (2025-12-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **afs:** set AFS tag for all AFS's skills ([#841](https://github.com/AIGNE-io/aigne-framework/issues/841)) ([0bd995a](https://github.com/AIGNE-io/aigne-framework/commit/0bd995aeb68aa68caac1ce19a200b42a022a9998))
|
|
9
|
+
* **afs:** use simple-list instead of tree as default type ([#839](https://github.com/AIGNE-io/aigne-framework/issues/839)) ([65a9a40](https://github.com/AIGNE-io/aigne-framework/commit/65a9a4054b3bdad6f7e40357299ef3dc48f7c3e4))
|
|
10
|
+
* **core:** add creditPrefix field to usage tracking ([#837](https://github.com/AIGNE-io/aigne-framework/issues/837)) ([9ef25e0](https://github.com/AIGNE-io/aigne-framework/commit/9ef25e0687b4e7b4ba39a27a35805f377f0979eb))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Dependencies
|
|
14
|
+
|
|
15
|
+
* The following workspace dependencies were updated
|
|
16
|
+
* dependencies
|
|
17
|
+
* @aigne/afs bumped to 1.4.0-beta.2
|
|
18
|
+
* @aigne/afs-history bumped to 1.2.0-beta.2
|
|
19
|
+
|
|
20
|
+
## [1.72.0-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta...core-v1.72.0-beta.1) (2025-12-17)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* bump version ([70d217c](https://github.com/AIGNE-io/aigne-framework/commit/70d217c8360dd0dda7f5f17011c4e92ec836e801))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
* The following workspace dependencies were updated
|
|
31
|
+
* dependencies
|
|
32
|
+
* @aigne/afs bumped to 1.4.0-beta.1
|
|
33
|
+
* @aigne/afs-history bumped to 1.2.0-beta.1
|
|
34
|
+
* @aigne/observability-api bumped to 0.11.14-beta
|
|
35
|
+
* @aigne/platform-helpers bumped to 0.6.7-beta
|
|
36
|
+
|
|
37
|
+
## [1.72.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0...core-v1.72.0-beta) (2025-12-17)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
* **afs:** support expand context into prompt template by call `$afs.xxx` ([#830](https://github.com/AIGNE-io/aigne-framework/issues/830)) ([5616acd](https://github.com/AIGNE-io/aigne-framework/commit/5616acd6ea257c91aa0b766608f45c5ce17f0345))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Dependencies
|
|
46
|
+
|
|
47
|
+
* The following workspace dependencies were updated
|
|
48
|
+
* dependencies
|
|
49
|
+
* @aigne/afs bumped to 1.4.0-beta
|
|
50
|
+
* @aigne/afs-history bumped to 1.2.0-beta
|
|
51
|
+
|
|
3
52
|
## [1.71.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.6...core-v1.71.0) (2025-12-12)
|
|
4
53
|
|
|
5
54
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AFS, type
|
|
1
|
+
import { AFS, type AFSExecOptions, type AFSExecResult, type AFSListOptions, type AFSListResult, type AFSModule, type AFSOptions, type AFSReadResult, type AFSSearchOptions } from "@aigne/afs";
|
|
2
2
|
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
3
3
|
import type * as prompts from "@inquirer/prompts";
|
|
4
4
|
import { type ZodObject, type ZodType } from "zod";
|
|
@@ -573,23 +573,10 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
573
573
|
/** For AFSModule interface **/
|
|
574
574
|
private agentToAFSEntry;
|
|
575
575
|
private findAgentByAFSPath;
|
|
576
|
-
list(_path: string, _options?: AFSListOptions): Promise<
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
read(path: string): Promise<{
|
|
581
|
-
result?: AFSEntry;
|
|
582
|
-
message?: string;
|
|
583
|
-
}>;
|
|
584
|
-
search(path: string, _query: string, options?: AFSSearchOptions): Promise<{
|
|
585
|
-
list: AFSEntry[];
|
|
586
|
-
message?: string;
|
|
587
|
-
}>;
|
|
588
|
-
exec(path: string, args: Record<string, any>, options: {
|
|
589
|
-
context: Context;
|
|
590
|
-
}): Promise<{
|
|
591
|
-
result: Record<string, any>;
|
|
592
|
-
}>;
|
|
576
|
+
list(_path: string, _options?: AFSListOptions): Promise<AFSListResult>;
|
|
577
|
+
read(path: string): Promise<AFSReadResult>;
|
|
578
|
+
search(path: string, _query: string, options?: AFSSearchOptions): Promise<AFSListResult>;
|
|
579
|
+
exec(path: string, args: Record<string, any>, options: AFSExecOptions): Promise<AFSExecResult>;
|
|
593
580
|
}
|
|
594
581
|
export type AgentInput<T extends Agent> = T extends Agent<infer I, any> ? I : never;
|
|
595
582
|
export type AgentOutput<T extends Agent> = T extends Agent<any, infer O> ? O : never;
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -781,7 +781,7 @@ class Agent {
|
|
|
781
781
|
// TODO: support list skills inside agent path, and use options to filter skills
|
|
782
782
|
async list(_path, _options) {
|
|
783
783
|
const agents = [this, ...this.skills];
|
|
784
|
-
return {
|
|
784
|
+
return { data: agents.map((agent) => this.agentToAFSEntry(agent)) };
|
|
785
785
|
}
|
|
786
786
|
async read(path) {
|
|
787
787
|
const agent = this.findAgentByAFSPath(path);
|
|
@@ -789,7 +789,7 @@ class Agent {
|
|
|
789
789
|
return { message: `Agent not found at path: ${path}` };
|
|
790
790
|
}
|
|
791
791
|
return {
|
|
792
|
-
|
|
792
|
+
data: this.agentToAFSEntry(agent),
|
|
793
793
|
};
|
|
794
794
|
}
|
|
795
795
|
// TODO: implement search inside agent skills
|
|
@@ -800,7 +800,7 @@ class Agent {
|
|
|
800
800
|
const agent = this.findAgentByAFSPath(path);
|
|
801
801
|
if (!agent)
|
|
802
802
|
throw new Error(`Agent not found at path: ${path}`);
|
|
803
|
-
return {
|
|
803
|
+
return { data: await options.context.invoke(agent, args) };
|
|
804
804
|
}
|
|
805
805
|
}
|
|
806
806
|
exports.Agent = Agent;
|
|
@@ -492,17 +492,24 @@ export interface ChatModelOutputUsage {
|
|
|
492
492
|
* AIGNE Hub credit usage
|
|
493
493
|
*/
|
|
494
494
|
aigneHubCredits?: number;
|
|
495
|
+
/**
|
|
496
|
+
* Credit prefix
|
|
497
|
+
*/
|
|
498
|
+
creditPrefix?: "$" | "€" | "¥";
|
|
495
499
|
}
|
|
496
500
|
export declare const chatModelOutputUsageSchema: z.ZodObject<{
|
|
497
501
|
inputTokens: z.ZodNumber;
|
|
498
502
|
outputTokens: z.ZodNumber;
|
|
499
503
|
aigneHubCredits: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
504
|
+
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
500
505
|
}, "strip", z.ZodTypeAny, {
|
|
501
506
|
inputTokens: number;
|
|
502
507
|
outputTokens: number;
|
|
503
508
|
aigneHubCredits?: number | undefined;
|
|
509
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
504
510
|
}, {
|
|
505
511
|
inputTokens: number;
|
|
506
512
|
outputTokens: number;
|
|
507
513
|
aigneHubCredits?: number | undefined;
|
|
514
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
508
515
|
}>;
|
|
@@ -225,6 +225,8 @@ class ChatModel extends model_js_1.Model {
|
|
|
225
225
|
options.context.usage.inputTokens += usage.inputTokens;
|
|
226
226
|
if (usage.aigneHubCredits)
|
|
227
227
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
228
|
+
if (usage.creditPrefix)
|
|
229
|
+
options.context.usage.creditPrefix = usage.creditPrefix;
|
|
228
230
|
}
|
|
229
231
|
}
|
|
230
232
|
async processAgentOutput(input, output, options) {
|
|
@@ -377,6 +379,7 @@ exports.chatModelOutputUsageSchema = zod_1.z.object({
|
|
|
377
379
|
inputTokens: zod_1.z.number(),
|
|
378
380
|
outputTokens: zod_1.z.number(),
|
|
379
381
|
aigneHubCredits: (0, schema_js_1.optionalize)(zod_1.z.number()),
|
|
382
|
+
creditPrefix: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("$"), zod_1.z.literal("€"), zod_1.z.literal("¥")])),
|
|
380
383
|
});
|
|
381
384
|
const chatModelOutputSchema = zod_1.z.object({
|
|
382
385
|
text: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
@@ -196,14 +196,17 @@ 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
|
+
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
199
200
|
}, "strip", z.ZodTypeAny, {
|
|
200
201
|
inputTokens: number;
|
|
201
202
|
outputTokens: number;
|
|
202
203
|
aigneHubCredits?: number | undefined;
|
|
204
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
203
205
|
}, {
|
|
204
206
|
inputTokens: number;
|
|
205
207
|
outputTokens: number;
|
|
206
208
|
aigneHubCredits?: number | undefined;
|
|
209
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
207
210
|
}>>;
|
|
208
211
|
model: z.ZodOptional<z.ZodString>;
|
|
209
212
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -228,6 +231,7 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
228
231
|
inputTokens: number;
|
|
229
232
|
outputTokens: number;
|
|
230
233
|
aigneHubCredits?: number | undefined;
|
|
234
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
231
235
|
} | undefined;
|
|
232
236
|
}, {
|
|
233
237
|
images: ({
|
|
@@ -251,5 +255,6 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
251
255
|
inputTokens: number;
|
|
252
256
|
outputTokens: number;
|
|
253
257
|
aigneHubCredits?: number | undefined;
|
|
258
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
254
259
|
} | undefined;
|
|
255
260
|
}>;
|
|
@@ -61,6 +61,8 @@ class ImageModel extends model_js_1.Model {
|
|
|
61
61
|
options.context.usage.inputTokens += usage.inputTokens;
|
|
62
62
|
if (usage.aigneHubCredits)
|
|
63
63
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
64
|
+
if (usage.creditPrefix)
|
|
65
|
+
options.context.usage.creditPrefix = usage.creditPrefix;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
async processAgentOutput(input, output, options) {
|
|
@@ -203,14 +203,17 @@ 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
|
+
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
206
207
|
}, "strip", z.ZodTypeAny, {
|
|
207
208
|
inputTokens: number;
|
|
208
209
|
outputTokens: number;
|
|
209
210
|
aigneHubCredits?: number | undefined;
|
|
211
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
210
212
|
}, {
|
|
211
213
|
inputTokens: number;
|
|
212
214
|
outputTokens: number;
|
|
213
215
|
aigneHubCredits?: number | undefined;
|
|
216
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
214
217
|
}>>;
|
|
215
218
|
model: z.ZodOptional<z.ZodString>;
|
|
216
219
|
seconds: z.ZodOptional<z.ZodNumber>;
|
|
@@ -236,6 +239,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
236
239
|
inputTokens: number;
|
|
237
240
|
outputTokens: number;
|
|
238
241
|
aigneHubCredits?: number | undefined;
|
|
242
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
239
243
|
} | undefined;
|
|
240
244
|
seconds?: number | undefined;
|
|
241
245
|
}, {
|
|
@@ -260,6 +264,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
260
264
|
inputTokens: number;
|
|
261
265
|
outputTokens: number;
|
|
262
266
|
aigneHubCredits?: number | undefined;
|
|
267
|
+
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
263
268
|
} | undefined;
|
|
264
269
|
seconds?: number | undefined;
|
|
265
270
|
}>;
|
|
@@ -34,6 +34,8 @@ class VideoModel extends model_js_1.Model {
|
|
|
34
34
|
options.context.usage.inputTokens += usage.inputTokens;
|
|
35
35
|
if (usage.aigneHubCredits)
|
|
36
36
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
37
|
+
if (usage.creditPrefix)
|
|
38
|
+
options.context.usage.creditPrefix = usage.creditPrefix;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
async processAgentOutput(input, output, options) {
|
package/lib/cjs/aigne/usage.d.ts
CHANGED
|
@@ -25,6 +25,26 @@ export type AFSModuleSchema = string | {
|
|
|
25
25
|
module: string;
|
|
26
26
|
options?: Record<string, any>;
|
|
27
27
|
};
|
|
28
|
+
export interface AFSContextPresetSchema {
|
|
29
|
+
view?: string;
|
|
30
|
+
select?: {
|
|
31
|
+
agent: NestAgentSchema;
|
|
32
|
+
};
|
|
33
|
+
per?: {
|
|
34
|
+
agent: NestAgentSchema;
|
|
35
|
+
};
|
|
36
|
+
dedupe?: {
|
|
37
|
+
agent: NestAgentSchema;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface AFSContextSchema {
|
|
41
|
+
search?: {
|
|
42
|
+
presets?: Record<string, AFSContextPresetSchema>;
|
|
43
|
+
};
|
|
44
|
+
list?: {
|
|
45
|
+
presets?: Record<string, AFSContextPresetSchema>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
28
48
|
export interface BaseAgentSchema {
|
|
29
49
|
name?: string;
|
|
30
50
|
description?: string;
|
|
@@ -42,8 +62,9 @@ export interface BaseAgentSchema {
|
|
|
42
62
|
provider: string;
|
|
43
63
|
subscribeTopic?: string[];
|
|
44
64
|
};
|
|
45
|
-
afs?: boolean | (Omit<AFSOptions, "modules"> & {
|
|
65
|
+
afs?: boolean | (Omit<AFSOptions, "modules" | "context"> & {
|
|
46
66
|
modules?: AFSModuleSchema[];
|
|
67
|
+
context?: AFSContextSchema;
|
|
47
68
|
});
|
|
48
69
|
shareAFS?: boolean;
|
|
49
70
|
}
|
|
@@ -86,6 +86,20 @@ const getAgentSchema = ({ filepath, options, }) => {
|
|
|
86
86
|
onSkillEnd: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
87
87
|
onHandoff: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
88
88
|
}));
|
|
89
|
+
const afsContextPresetsSchema = zod_1.z.object({
|
|
90
|
+
presets: (0, schema_js_1.optionalize)(zod_1.z.record(zod_1.z.string(), zod_1.z.object({
|
|
91
|
+
view: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
92
|
+
select: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
93
|
+
agent: nestAgentSchema,
|
|
94
|
+
})),
|
|
95
|
+
per: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
96
|
+
agent: nestAgentSchema,
|
|
97
|
+
})),
|
|
98
|
+
dedupe: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
99
|
+
agent: nestAgentSchema,
|
|
100
|
+
})),
|
|
101
|
+
}))),
|
|
102
|
+
});
|
|
89
103
|
const baseAgentSchema = zod_1.z.object({
|
|
90
104
|
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
91
105
|
alias: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
|
|
@@ -117,6 +131,10 @@ const getAgentSchema = ({ filepath, options, }) => {
|
|
|
117
131
|
options: (0, schema_js_1.optionalize)(zod_1.z.record(zod_1.z.any())),
|
|
118
132
|
})),
|
|
119
133
|
]))),
|
|
134
|
+
context: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
135
|
+
search: (0, schema_js_1.optionalize)(afsContextPresetsSchema),
|
|
136
|
+
list: (0, schema_js_1.optionalize)(afsContextPresetsSchema),
|
|
137
|
+
})),
|
|
120
138
|
})),
|
|
121
139
|
])),
|
|
122
140
|
shareAFS: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
package/lib/cjs/loader/index.js
CHANGED
|
@@ -132,7 +132,32 @@ async function parseAgent(path, agent, options, agentOptions) {
|
|
|
132
132
|
afs = new afs_1.AFS();
|
|
133
133
|
}
|
|
134
134
|
else if (agent.afs) {
|
|
135
|
-
afs = new afs_1.AFS();
|
|
135
|
+
afs = new afs_1.AFS({});
|
|
136
|
+
const loadAFSContextPresets = async (presets) => {
|
|
137
|
+
return Object.fromEntries(await Promise.all(Object.entries(presets).map(async ([key, value]) => {
|
|
138
|
+
const [select, per, dedupe] = await Promise.all([value.select, value.per, value.dedupe].map(async (item) => {
|
|
139
|
+
if (!item?.agent)
|
|
140
|
+
return undefined;
|
|
141
|
+
const agent = await loadNestAgent(path, item.agent, options, { afs });
|
|
142
|
+
return {
|
|
143
|
+
invoke: (input, options) => options.context.invoke(agent, input, {
|
|
144
|
+
...options,
|
|
145
|
+
streaming: false,
|
|
146
|
+
}),
|
|
147
|
+
};
|
|
148
|
+
}));
|
|
149
|
+
return [key, { ...value, select, per, dedupe }];
|
|
150
|
+
})));
|
|
151
|
+
};
|
|
152
|
+
const context = {
|
|
153
|
+
search: {
|
|
154
|
+
presets: await loadAFSContextPresets(agent.afs.context?.search?.presets || {}),
|
|
155
|
+
},
|
|
156
|
+
list: {
|
|
157
|
+
presets: await loadAFSContextPresets(agent.afs.context?.list?.presets || {}),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
afs.options.context = context;
|
|
136
161
|
for (const m of agent.afs.modules || []) {
|
|
137
162
|
const moduleName = typeof m === "string" ? m : m.module;
|
|
138
163
|
const mod = options?.afs?.availableModules?.find((mod) => mod.module === moduleName || mod.alias?.includes(moduleName));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHistories = getHistories;
|
|
4
|
+
const afs_history_1 = require("@aigne/afs-history");
|
|
5
|
+
const type_utils_js_1 = require("../../../utils/type-utils.js");
|
|
6
|
+
async function getHistories(agent) {
|
|
7
|
+
const afs = agent?.afs;
|
|
8
|
+
if (!afs)
|
|
9
|
+
return [];
|
|
10
|
+
const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
|
|
11
|
+
if (!historyModule)
|
|
12
|
+
return [];
|
|
13
|
+
const history = (await afs.list(historyModule.path, {
|
|
14
|
+
limit: agent.historyConfig?.maxItems || 10,
|
|
15
|
+
orderBy: [["createdAt", "desc"]],
|
|
16
|
+
})).data;
|
|
17
|
+
return history
|
|
18
|
+
.reverse()
|
|
19
|
+
.map((i) => {
|
|
20
|
+
if (!i.content)
|
|
21
|
+
return;
|
|
22
|
+
const { input, output } = i.content;
|
|
23
|
+
if (!input || !output)
|
|
24
|
+
return;
|
|
25
|
+
return [
|
|
26
|
+
{ role: "user", content: input },
|
|
27
|
+
{ role: "agent", content: output },
|
|
28
|
+
];
|
|
29
|
+
})
|
|
30
|
+
.filter(type_utils_js_1.isNonNullable)
|
|
31
|
+
.flat();
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AFSRootListOptions, AFSRootSearchOptions } from "@aigne/afs";
|
|
2
|
+
import type { Agent, AgentInvokeOptions } from "../../../agents/agent.js";
|
|
3
|
+
export declare function createAFSContext(agent?: Agent<any, any>, context?: AgentInvokeOptions["context"]): {
|
|
4
|
+
readonly enabled: boolean;
|
|
5
|
+
description: string;
|
|
6
|
+
readonly modules: Promise<Pick<{
|
|
7
|
+
name: string;
|
|
8
|
+
path: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
module: import("@aigne/afs").AFSModule;
|
|
11
|
+
}, "path" | "name" | "description">[]> | undefined;
|
|
12
|
+
readonly histories: Promise<{
|
|
13
|
+
role: "user" | "agent";
|
|
14
|
+
content: unknown;
|
|
15
|
+
}[]>;
|
|
16
|
+
readonly skills: never[] | Promise<Pick<Agent<any, any>, "name" | "description">[]>;
|
|
17
|
+
list(path: string, options?: AFSRootListOptions): Promise<any>;
|
|
18
|
+
read(path: string): Promise<import("@aigne/afs").AFSEntry<any> | undefined>;
|
|
19
|
+
search(path: string, query: string, options?: AFSRootSearchOptions): Promise<any>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAFSContext = createAFSContext;
|
|
4
|
+
const type_utils_js_1 = require("../../../utils/type-utils.js");
|
|
5
|
+
const afs_builtin_prompt_js_1 = require("../../prompts/afs-builtin-prompt.js");
|
|
6
|
+
const index_js_1 = require("../../skills/afs/index.js");
|
|
7
|
+
const history_js_1 = require("./history.js");
|
|
8
|
+
function createAFSContext(agent, context) {
|
|
9
|
+
const afs = agent?.afs;
|
|
10
|
+
return {
|
|
11
|
+
get enabled() {
|
|
12
|
+
return !!afs;
|
|
13
|
+
},
|
|
14
|
+
description: afs_builtin_prompt_js_1.AFS_DESCRIPTION_PROMPT_TEMPLATE,
|
|
15
|
+
get modules() {
|
|
16
|
+
return afs
|
|
17
|
+
?.listModules()
|
|
18
|
+
.then((list) => list.map((i) => (0, type_utils_js_1.pick)(i, ["name", "path", "description"])));
|
|
19
|
+
},
|
|
20
|
+
get histories() {
|
|
21
|
+
if (!agent)
|
|
22
|
+
return Promise.resolve([]);
|
|
23
|
+
return (0, history_js_1.getHistories)(agent);
|
|
24
|
+
},
|
|
25
|
+
get skills() {
|
|
26
|
+
const afs = agent?.afs;
|
|
27
|
+
if (!afs)
|
|
28
|
+
return [];
|
|
29
|
+
return (0, index_js_1.getAFSSkills)(afs).then((skills) => skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"])));
|
|
30
|
+
},
|
|
31
|
+
async list(path, options) {
|
|
32
|
+
if (!afs)
|
|
33
|
+
throw new Error("AFS is not configured for this agent.");
|
|
34
|
+
return (await afs.list(path, { ...options, context, format: options?.format || "simple-list" })).data;
|
|
35
|
+
},
|
|
36
|
+
async read(path) {
|
|
37
|
+
if (!afs)
|
|
38
|
+
throw new Error("AFS is not configured for this agent.");
|
|
39
|
+
return (await afs.read(path)).data;
|
|
40
|
+
},
|
|
41
|
+
async search(path, query, options = {}) {
|
|
42
|
+
if (!afs)
|
|
43
|
+
throw new Error("AFS is not configured for this agent.");
|
|
44
|
+
return (await afs.search(path, query, { ...options, context })).data;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PromptBuildOptions } from "../prompt-builder.js";
|
|
2
|
+
export declare function createPromptBuilderContext(options: PromptBuildOptions): {
|
|
3
|
+
$afs: {
|
|
4
|
+
readonly enabled: boolean;
|
|
5
|
+
description: string;
|
|
6
|
+
readonly modules: Promise<Pick<{
|
|
7
|
+
name: string;
|
|
8
|
+
path: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
module: import("@aigne/afs/.").AFSModule;
|
|
11
|
+
}, "path" | "name" | "description">[]> | undefined;
|
|
12
|
+
readonly histories: Promise<{
|
|
13
|
+
role: "user" | "agent";
|
|
14
|
+
content: unknown;
|
|
15
|
+
}[]>;
|
|
16
|
+
readonly skills: never[] | Promise<Pick<import("../../index.js").Agent<any, any>, "name" | "description">[]>;
|
|
17
|
+
list(path: string, options?: import("@aigne/afs/.").AFSRootListOptions): Promise<any>;
|
|
18
|
+
read(path: string): Promise<import("@aigne/afs/.").AFSEntry<any> | undefined>;
|
|
19
|
+
search(path: string, query: string, options?: import("@aigne/afs/.").AFSRootSearchOptions): Promise<any>;
|
|
20
|
+
};
|
|
21
|
+
$agent: {
|
|
22
|
+
readonly skills: Pick<import("../../index.js").Agent<any, any>, "name" | "description">[] | undefined;
|
|
23
|
+
};
|
|
24
|
+
$meta?: {
|
|
25
|
+
usage?: import("../../index.js").ContextUsage;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
userId?: string;
|
|
29
|
+
sessionId?: string;
|
|
30
|
+
userContext: import("../../index.js").UserContext | undefined;
|
|
31
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPromptBuilderContext = createPromptBuilderContext;
|
|
4
|
+
const type_utils_js_1 = require("../../utils/type-utils.js");
|
|
5
|
+
const index_js_1 = require("./afs/index.js");
|
|
6
|
+
function createPromptBuilderContext(options) {
|
|
7
|
+
return {
|
|
8
|
+
userContext: options.context?.userContext,
|
|
9
|
+
...options.context?.userContext,
|
|
10
|
+
...options.input,
|
|
11
|
+
$afs: (0, index_js_1.createAFSContext)(options.agent, options.context),
|
|
12
|
+
$agent: {
|
|
13
|
+
get skills() {
|
|
14
|
+
return options.agent?.skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"]));
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -12,10 +12,11 @@ const model_js_1 = require("../agents/model.js");
|
|
|
12
12
|
const schema_js_1 = require("../loader/schema.js");
|
|
13
13
|
const json_schema_js_1 = require("../utils/json-schema.js");
|
|
14
14
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
15
|
+
const index_js_2 = require("./context/index.js");
|
|
15
16
|
const afs_builtin_prompt_js_1 = require("./prompts/afs-builtin-prompt.js");
|
|
16
17
|
const memory_message_template_js_1 = require("./prompts/memory-message-template.js");
|
|
17
18
|
const structured_stream_instructions_js_1 = require("./prompts/structured-stream-instructions.js");
|
|
18
|
-
const
|
|
19
|
+
const index_js_3 = require("./skills/afs/index.js");
|
|
19
20
|
const template_js_1 = require("./template.js");
|
|
20
21
|
class PromptBuilder {
|
|
21
22
|
static from(instructions, { workingDir } = {}) {
|
|
@@ -95,37 +96,7 @@ class PromptBuilder {
|
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
getTemplateVariables(options) {
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
userContext: options.context?.userContext,
|
|
101
|
-
...options.context?.userContext,
|
|
102
|
-
...options.input,
|
|
103
|
-
$afs: {
|
|
104
|
-
get enabled() {
|
|
105
|
-
return !!options.agent?.afs;
|
|
106
|
-
},
|
|
107
|
-
description: afs_builtin_prompt_js_1.AFS_DESCRIPTION_PROMPT_TEMPLATE,
|
|
108
|
-
get modules() {
|
|
109
|
-
return options.agent?.afs
|
|
110
|
-
?.listModules()
|
|
111
|
-
.then((list) => list.map((i) => (0, type_utils_js_1.pick)(i, ["name", "path", "description"])));
|
|
112
|
-
},
|
|
113
|
-
get histories() {
|
|
114
|
-
return self.getHistories(options);
|
|
115
|
-
},
|
|
116
|
-
get skills() {
|
|
117
|
-
const afs = options.agent?.afs;
|
|
118
|
-
if (!afs)
|
|
119
|
-
return [];
|
|
120
|
-
return (0, index_js_2.getAFSSkills)(afs).then((skills) => skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"])));
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
$agent: {
|
|
124
|
-
get skills() {
|
|
125
|
-
return options.agent?.skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"]));
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
99
|
+
return (0, index_js_2.createPromptBuilderContext)(options);
|
|
129
100
|
}
|
|
130
101
|
async buildMessages(options) {
|
|
131
102
|
const { input } = options;
|
|
@@ -154,12 +125,12 @@ class PromptBuilder {
|
|
|
154
125
|
limit: options.agent?.maxRetrieveMemoryCount || 10,
|
|
155
126
|
orderBy: [["createdAt", "desc"]],
|
|
156
127
|
});
|
|
157
|
-
memories.push(...history.
|
|
128
|
+
memories.push(...history.data
|
|
158
129
|
.reverse()
|
|
159
130
|
.filter((i) => (0, type_utils_js_1.isNonNullable)(i.content)));
|
|
160
131
|
if (message) {
|
|
161
|
-
const result = await afs.search("/", message);
|
|
162
|
-
const ms = result
|
|
132
|
+
const result = (await afs.search("/", message)).data;
|
|
133
|
+
const ms = result
|
|
163
134
|
.map((entry) => {
|
|
164
135
|
if (entry.metadata?.execute)
|
|
165
136
|
return null;
|
|
@@ -173,7 +144,7 @@ class PromptBuilder {
|
|
|
173
144
|
})
|
|
174
145
|
.filter(type_utils_js_1.isNonNullable);
|
|
175
146
|
memories.push(...ms);
|
|
176
|
-
const executable = result.
|
|
147
|
+
const executable = result.filter((i) => !!i.metadata?.execute);
|
|
177
148
|
if (executable.length) {
|
|
178
149
|
messages.push({
|
|
179
150
|
role: "system",
|
|
@@ -232,10 +203,10 @@ class PromptBuilder {
|
|
|
232
203
|
const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
|
|
233
204
|
if (!historyModule)
|
|
234
205
|
return [];
|
|
235
|
-
const
|
|
206
|
+
const history = (await afs.list(historyModule.path, {
|
|
236
207
|
limit: agent.historyConfig?.maxItems || 10,
|
|
237
208
|
orderBy: [["createdAt", "desc"]],
|
|
238
|
-
});
|
|
209
|
+
})).data;
|
|
239
210
|
return history
|
|
240
211
|
.reverse()
|
|
241
212
|
.map((i) => {
|
|
@@ -364,7 +335,7 @@ class PromptBuilder {
|
|
|
364
335
|
.concat(options.agent?.memoryAgentsAsTools ? options.agent.memories : [])
|
|
365
336
|
.flatMap((i) => (i.isInvokable ? i : i.skills)), (i) => i.name);
|
|
366
337
|
if (options.agent?.afs) {
|
|
367
|
-
toolAgents.push(...(await (0,
|
|
338
|
+
toolAgents.push(...(await (0, index_js_3.getAFSSkills)(options.agent.afs)));
|
|
368
339
|
}
|
|
369
340
|
const tools = toolAgents.map((i) => ({
|
|
370
341
|
type: "function",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AFSSkillBase = void 0;
|
|
4
|
+
const agent_js_1 = require("../../../agents/agent.js");
|
|
5
|
+
class AFSSkillBase extends agent_js_1.Agent {
|
|
6
|
+
tag = "AFS";
|
|
7
|
+
}
|
|
8
|
+
exports.AFSSkillBase = AFSSkillBase;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
|
|
2
|
+
import { AFSSkillBase } from "./base.js";
|
|
2
3
|
export interface AFSDeleteInput extends Message {
|
|
3
4
|
path: string;
|
|
4
5
|
recursive?: boolean;
|
|
@@ -12,7 +13,7 @@ export interface AFSDeleteOutput extends Message {
|
|
|
12
13
|
export interface AFSDeleteAgentOptions extends AgentOptions<AFSDeleteInput, AFSDeleteOutput> {
|
|
13
14
|
afs: NonNullable<AgentOptions<AFSDeleteInput, AFSDeleteOutput>["afs"]>;
|
|
14
15
|
}
|
|
15
|
-
export declare class AFSDeleteAgent extends
|
|
16
|
+
export declare class AFSDeleteAgent extends AFSSkillBase<AFSDeleteInput, AFSDeleteOutput> {
|
|
16
17
|
constructor(options: AFSDeleteAgentOptions);
|
|
17
18
|
process(input: AFSDeleteInput, _options: AgentInvokeOptions): Promise<AFSDeleteOutput>;
|
|
18
19
|
}
|