@aigne/core 1.72.0-beta.9 → 1.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +342 -0
- package/lib/cjs/agents/agent.d.ts +5 -0
- package/lib/cjs/agents/agent.js +5 -0
- package/lib/cjs/agents/ai-agent.d.ts +41 -5
- package/lib/cjs/agents/ai-agent.js +89 -29
- package/lib/cjs/agents/chat-model.d.ts +3 -0
- package/lib/cjs/agents/chat-model.js +18 -1
- package/lib/cjs/agents/image-model.js +1 -1
- package/lib/cjs/agents/model.d.ts +3 -3
- package/lib/cjs/agents/model.js +2 -2
- package/lib/cjs/agents/video-model.js +1 -1
- package/lib/cjs/aigne/context.js +1 -3
- package/lib/cjs/prompt/agent-session.d.ts +115 -5
- package/lib/cjs/prompt/agent-session.js +746 -83
- package/lib/cjs/prompt/compact/compactor.js +4 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.js +143 -0
- package/lib/cjs/prompt/compact/types.d.ts +257 -0
- package/lib/cjs/prompt/compact/types.js +35 -1
- package/lib/cjs/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/user-memory-extractor.js +124 -0
- package/lib/cjs/prompt/prompt-builder.js +3 -3
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +2 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +6 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +1 -2
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +14 -26
- package/lib/cjs/prompt/skills/afs/list.d.ts +2 -0
- package/lib/cjs/prompt/skills/afs/list.js +9 -1
- package/lib/cjs/prompt/skills/afs/read.d.ts +3 -1
- package/lib/cjs/prompt/skills/afs/read.js +5 -0
- package/lib/cjs/utils/mcp-utils.js +1 -1
- package/lib/cjs/utils/token-estimator.js +1 -1
- package/lib/cjs/utils/type-utils.js +0 -1
- package/lib/dts/agents/agent.d.ts +5 -0
- package/lib/dts/agents/ai-agent.d.ts +41 -5
- package/lib/dts/agents/chat-model.d.ts +3 -0
- package/lib/dts/agents/model.d.ts +3 -3
- package/lib/dts/prompt/agent-session.d.ts +115 -5
- package/lib/dts/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/compact/types.d.ts +257 -0
- package/lib/dts/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +2 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +1 -2
- package/lib/dts/prompt/skills/afs/list.d.ts +2 -0
- package/lib/dts/prompt/skills/afs/read.d.ts +3 -1
- package/lib/esm/agents/agent.d.ts +5 -0
- package/lib/esm/agents/agent.js +5 -0
- package/lib/esm/agents/ai-agent.d.ts +41 -5
- package/lib/esm/agents/ai-agent.js +89 -29
- package/lib/esm/agents/chat-model.d.ts +3 -0
- package/lib/esm/agents/chat-model.js +18 -1
- package/lib/esm/agents/image-model.js +1 -1
- package/lib/esm/agents/model.d.ts +3 -3
- package/lib/esm/agents/model.js +2 -2
- package/lib/esm/agents/video-model.js +1 -1
- package/lib/esm/aigne/context.js +2 -4
- package/lib/esm/prompt/agent-session.d.ts +115 -5
- package/lib/esm/prompt/agent-session.js +744 -84
- package/lib/esm/prompt/compact/compactor.js +4 -0
- package/lib/esm/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/session-memory-extractor.js +139 -0
- package/lib/esm/prompt/compact/types.d.ts +257 -0
- package/lib/esm/prompt/compact/types.js +34 -0
- package/lib/esm/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/user-memory-extractor.js +120 -0
- package/lib/esm/prompt/prompt-builder.js +3 -3
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +2 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +6 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +1 -2
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +13 -24
- package/lib/esm/prompt/skills/afs/list.d.ts +2 -0
- package/lib/esm/prompt/skills/afs/list.js +9 -1
- package/lib/esm/prompt/skills/afs/read.d.ts +3 -1
- package/lib/esm/prompt/skills/afs/read.js +5 -0
- package/lib/esm/utils/mcp-utils.js +1 -1
- package/lib/esm/utils/token-estimator.js +1 -1
- package/lib/esm/utils/type-utils.js +0 -1
- package/package.json +6 -6
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
2
1
|
import fm from "front-matter";
|
|
3
2
|
import { AgentSkill } from "./agent-skill.js";
|
|
4
3
|
function parseSkill(content, path) {
|
|
@@ -10,42 +9,32 @@ function parseSkill(content, path) {
|
|
|
10
9
|
content: meta.body,
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
|
-
export async function
|
|
14
|
-
const entry = nodejs.path.join(path, "SKILL.md");
|
|
15
|
-
const skill = await nodejs.fs.readFile(entry, "utf-8");
|
|
16
|
-
return parseSkill(skill, path);
|
|
17
|
-
}
|
|
18
|
-
export async function loadSkills(paths) {
|
|
19
|
-
const skills = [];
|
|
20
|
-
for (const path of paths) {
|
|
21
|
-
const skill = await loadSkill(path);
|
|
22
|
-
skills.push(skill);
|
|
23
|
-
}
|
|
24
|
-
return skills;
|
|
25
|
-
}
|
|
26
|
-
export async function loadAgentSkillFromAFS({ afs, }) {
|
|
12
|
+
export async function discoverSkillsFromAFS(afs) {
|
|
27
13
|
const modules = await afs.listModules();
|
|
28
|
-
const filtered = modules.filter(({ module: m }) =>
|
|
29
|
-
typeof m.options === "object" &&
|
|
30
|
-
m.options &&
|
|
31
|
-
"agentSkills" in m.options &&
|
|
32
|
-
m.options.agentSkills === true);
|
|
14
|
+
const filtered = modules.filter(({ module: m }) => m.agentSkills === true);
|
|
33
15
|
if (!filtered.length)
|
|
34
|
-
return;
|
|
16
|
+
return [];
|
|
35
17
|
const skills = [];
|
|
36
18
|
for (const module of filtered) {
|
|
37
|
-
const data = (await afs
|
|
19
|
+
const data = (await afs
|
|
20
|
+
.list(module.path, {
|
|
38
21
|
pattern: "**/SKILL.md",
|
|
39
22
|
maxDepth: 10,
|
|
40
|
-
})
|
|
23
|
+
})
|
|
24
|
+
.catch(() => ({ data: [] }))).data;
|
|
41
25
|
for (const entry of data) {
|
|
42
26
|
const { data: file } = await afs.read(entry.path);
|
|
43
27
|
if (typeof file?.content !== "string")
|
|
44
28
|
continue;
|
|
45
|
-
const
|
|
29
|
+
const dirname = entry.path.split("/").slice(0, -1).join("/");
|
|
30
|
+
const skill = parseSkill(file.content, dirname);
|
|
46
31
|
skills.push(skill);
|
|
47
32
|
}
|
|
48
33
|
}
|
|
34
|
+
return skills;
|
|
35
|
+
}
|
|
36
|
+
export async function loadAgentSkillFromAFS({ afs, }) {
|
|
37
|
+
const skills = await discoverSkillsFromAFS(afs);
|
|
49
38
|
if (!skills.length)
|
|
50
39
|
return;
|
|
51
40
|
return new AgentSkill({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AFSListOptions } from "@aigne/afs";
|
|
2
2
|
import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
|
|
3
|
+
import type { PromiseOrValue } from "../../../utils/type-utils.js";
|
|
3
4
|
import { AFSSkillBase } from "./base.js";
|
|
4
5
|
export interface AFSListInput extends Message {
|
|
5
6
|
path: string;
|
|
@@ -18,5 +19,6 @@ export interface AFSListAgentOptions extends AgentOptions<AFSListInput, AFSListO
|
|
|
18
19
|
}
|
|
19
20
|
export declare class AFSListAgent extends AFSSkillBase<AFSListInput, AFSListOutput> {
|
|
20
21
|
constructor(options: AFSListAgentOptions);
|
|
22
|
+
formatOutput(output: AFSListOutput): PromiseOrValue<string>;
|
|
21
23
|
process(input: AFSListInput, _options: AgentInvokeOptions): Promise<AFSListOutput>;
|
|
22
24
|
}
|
|
@@ -53,10 +53,18 @@ Usage:
|
|
|
53
53
|
}),
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
+
formatOutput(output) {
|
|
57
|
+
if (typeof output.data === "string")
|
|
58
|
+
return output.data;
|
|
59
|
+
return super.formatOutput(output);
|
|
60
|
+
}
|
|
56
61
|
async process(input, _options) {
|
|
57
62
|
if (!this.afs)
|
|
58
63
|
throw new Error("AFS is not configured for this agent.");
|
|
59
|
-
const { data, message } = await this.afs.list(input.path,
|
|
64
|
+
const { data, message } = await this.afs.list(input.path, {
|
|
65
|
+
...input.options,
|
|
66
|
+
format: "simple-list",
|
|
67
|
+
});
|
|
60
68
|
return {
|
|
61
69
|
status: "success",
|
|
62
70
|
tool: "afs_list",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AFSEntry } from "@aigne/afs";
|
|
2
2
|
import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
|
|
3
|
+
import type { PromiseOrValue } from "../../../utils/type-utils.js";
|
|
3
4
|
import { AFSSkillBase } from "./base.js";
|
|
4
5
|
export interface AFSReadInput extends Message {
|
|
5
6
|
path: string;
|
|
@@ -10,7 +11,7 @@ export interface AFSReadOutput extends Message {
|
|
|
10
11
|
status: string;
|
|
11
12
|
tool: string;
|
|
12
13
|
path: string;
|
|
13
|
-
data?: AFSEntry;
|
|
14
|
+
data?: AFSEntry | null;
|
|
14
15
|
message?: string;
|
|
15
16
|
totalLines?: number;
|
|
16
17
|
returnedLines?: number;
|
|
@@ -22,5 +23,6 @@ export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadO
|
|
|
22
23
|
}
|
|
23
24
|
export declare class AFSReadAgent extends AFSSkillBase<AFSReadInput, AFSReadOutput> {
|
|
24
25
|
constructor(options: AFSReadAgentOptions);
|
|
26
|
+
formatOutput(output: AFSReadOutput): PromiseOrValue<string>;
|
|
25
27
|
process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
|
|
26
28
|
}
|
|
@@ -48,6 +48,11 @@ Usage:
|
|
|
48
48
|
}),
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
+
formatOutput(output) {
|
|
52
|
+
if (typeof output.data?.content === "string" && output.data.content)
|
|
53
|
+
return output.data.content;
|
|
54
|
+
return super.formatOutput({ ...output, data: output.data || null });
|
|
55
|
+
}
|
|
51
56
|
async process(input, _options) {
|
|
52
57
|
if (!this.afs)
|
|
53
58
|
throw new Error("AFS is not configured for this agent.");
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
const CHAR_TYPE_RATIOS = {
|
|
6
6
|
chinese: 1.5, // Chinese characters: ~1.5 characters per token
|
|
7
7
|
word: 0.75, // English words: ~0.75 tokens per word (accounting for subword tokenization)
|
|
8
|
-
other:
|
|
8
|
+
other: 1, // Other characters (punctuation, numbers, etc.): ~1 character per token
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Regular expressions for character type detection
|
|
@@ -37,7 +37,6 @@ export function duplicates(arr, key = (item) => item) {
|
|
|
37
37
|
export function remove(arr, remove) {
|
|
38
38
|
const removed = [];
|
|
39
39
|
for (let i = 0; i < arr.length; i++) {
|
|
40
|
-
// biome-ignore lint/style/noNonNullAssertion: false positive
|
|
41
40
|
const item = arr[i];
|
|
42
41
|
if ((Array.isArray(remove) && remove.includes(item)) ||
|
|
43
42
|
(typeof remove === "function" && remove(item))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.72.0
|
|
3
|
+
"version": "1.72.0",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"front-matter": "^4.0.2",
|
|
82
82
|
"immer": "^10.1.3",
|
|
83
83
|
"is-network-error": "^1.2.0",
|
|
84
|
-
"jaison": "
|
|
84
|
+
"jaison": "=2.0.2",
|
|
85
85
|
"jsonata": "^2.1.0",
|
|
86
86
|
"mime": "^4.1.0",
|
|
87
87
|
"nunjucks": "^3.2.4",
|
|
@@ -93,10 +93,10 @@
|
|
|
93
93
|
"zod": "^3.25.67",
|
|
94
94
|
"zod-from-json-schema": "^0.0.5",
|
|
95
95
|
"zod-to-json-schema": "^3.24.6",
|
|
96
|
-
"@aigne/afs": "^1.4.0
|
|
97
|
-
"@aigne/platform-helpers": "^0.6.7
|
|
98
|
-
"@aigne/observability-api": "^0.11.14
|
|
99
|
-
"@aigne/afs-history": "^1.2.0
|
|
96
|
+
"@aigne/afs": "^1.4.0",
|
|
97
|
+
"@aigne/platform-helpers": "^0.6.7",
|
|
98
|
+
"@aigne/observability-api": "^0.11.14",
|
|
99
|
+
"@aigne/afs-history": "^1.2.0"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@types/bun": "^1.2.22",
|