@eoasmxd/freya 0.5.0 → 0.5.1
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/core/dist/prompt/prompt-registry.d.ts +4 -4
- package/core/dist/prompt/prompt-registry.js +33 -14
- package/core/package.json +2 -2
- package/package.json +2 -2
- package/plugins/plugin-gemini/package.json +1 -1
- package/plugins/plugin-openai/package.json +1 -1
- package/plugins/plugin-telegram-channel/package.json +1 -1
- package/plugins/plugin-tool-fs/package.json +1 -1
- package/plugins/plugin-tool-memory/package.json +1 -1
- package/plugins/plugin-tool-mysql/package.json +1 -1
- package/plugins/plugin-tool-web/package.json +1 -1
- package/plugins/plugin-wecom-channel/package.json +1 -1
- package/plugins/plugin-weixin-channel/package.json +1 -1
- package/src/packages/core/src/prompt/prompt-registry.ts +39 -15
|
@@ -2,13 +2,13 @@ export interface FreyaPrompt {
|
|
|
2
2
|
key: string;
|
|
3
3
|
content: string;
|
|
4
4
|
defaultPath: string;
|
|
5
|
-
|
|
5
|
+
configFileName?: string;
|
|
6
6
|
}
|
|
7
7
|
/** 提示词内存注册表,管理所有系统及插件级提示词的分类检索 */
|
|
8
8
|
export declare class FreyaPromptRegistry {
|
|
9
9
|
private prompts;
|
|
10
|
-
private
|
|
11
|
-
/**
|
|
10
|
+
private resolveProbePaths;
|
|
11
|
+
/** 注册提示词元数据声明并执行三层级联探针载入 */
|
|
12
12
|
register(prompt: Omit<FreyaPrompt, 'content'>): Promise<void>;
|
|
13
13
|
/** 更新内存中的提示词文本内容 */
|
|
14
14
|
updateContent(key: string, content: string): void;
|
|
@@ -16,7 +16,7 @@ export declare class FreyaPromptRegistry {
|
|
|
16
16
|
unregister(key: string): void;
|
|
17
17
|
get(key: string): string;
|
|
18
18
|
getPrompts(): Map<string, FreyaPrompt>;
|
|
19
|
-
/**
|
|
19
|
+
/** 扫描并装载所有内核提示词 */
|
|
20
20
|
loadKernelPrompts(): Promise<void>;
|
|
21
21
|
/** 获取并拼装完整的核心 System Prompt */
|
|
22
22
|
getSystemPrompt(): string;
|
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { FREYA_APP, FREYA_HOME } from '../utils/paths.js';
|
|
3
|
+
import { FREYA_APP, FREYA_HOME, FREYA_WORKSPACE } from '../utils/paths.js';
|
|
4
4
|
/** 提示词内存注册表,管理所有系统及插件级提示词的分类检索 */
|
|
5
5
|
export class FreyaPromptRegistry {
|
|
6
6
|
prompts = new Map();
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
resolveProbePaths(prompt) {
|
|
8
|
+
const baseName = path.basename(prompt.defaultPath);
|
|
9
|
+
const rawPaths = [];
|
|
10
|
+
if (prompt.configFileName) {
|
|
11
|
+
rawPaths.push(path.join(FREYA_HOME, 'config', prompt.configFileName));
|
|
12
|
+
rawPaths.push(path.join(FREYA_WORKSPACE, 'config', prompt.configFileName));
|
|
13
|
+
}
|
|
14
|
+
rawPaths.push(path.join(FREYA_HOME, 'config', 'prompts', baseName));
|
|
15
|
+
rawPaths.push(path.join(FREYA_WORKSPACE, 'config', 'prompts', baseName));
|
|
16
|
+
rawPaths.push(prompt.defaultPath);
|
|
17
|
+
const candidates = [];
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
for (const rawPath of rawPaths) {
|
|
20
|
+
const normalized = path.resolve(rawPath);
|
|
21
|
+
if (!seen.has(normalized)) {
|
|
22
|
+
seen.add(normalized);
|
|
23
|
+
candidates.push(normalized);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return candidates;
|
|
9
27
|
}
|
|
10
|
-
/**
|
|
28
|
+
/** 注册提示词元数据声明并执行三层级联探针载入 */
|
|
11
29
|
async register(prompt) {
|
|
12
|
-
const
|
|
30
|
+
const probePaths = this.resolveProbePaths(prompt);
|
|
13
31
|
let content = '';
|
|
14
|
-
|
|
32
|
+
for (const filePath of probePaths) {
|
|
15
33
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
const text = await fs.readFile(filePath, 'utf-8');
|
|
35
|
+
if (text.trim().length > 0) {
|
|
36
|
+
content = text;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
20
39
|
}
|
|
40
|
+
catch { }
|
|
21
41
|
}
|
|
22
|
-
catch { }
|
|
23
42
|
this.prompts.set(prompt.key, {
|
|
24
43
|
key: prompt.key,
|
|
25
44
|
content: content.trim(),
|
|
26
45
|
defaultPath: prompt.defaultPath,
|
|
27
|
-
|
|
46
|
+
configFileName: prompt.configFileName
|
|
28
47
|
});
|
|
29
48
|
}
|
|
30
49
|
/** 更新内存中的提示词文本内容 */
|
|
@@ -44,7 +63,7 @@ export class FreyaPromptRegistry {
|
|
|
44
63
|
getPrompts() {
|
|
45
64
|
return this.prompts;
|
|
46
65
|
}
|
|
47
|
-
/**
|
|
66
|
+
/** 扫描并装载所有内核提示词 */
|
|
48
67
|
async loadKernelPrompts() {
|
|
49
68
|
const defaultDirPath = path.join(FREYA_APP, 'config', 'prompts');
|
|
50
69
|
try {
|
|
@@ -53,7 +72,7 @@ export class FreyaPromptRegistry {
|
|
|
53
72
|
await this.register({
|
|
54
73
|
key: `core.prompt.${name}`,
|
|
55
74
|
defaultPath: path.join(defaultDirPath, `core.prompt.${name}.md`),
|
|
56
|
-
|
|
75
|
+
configFileName: `${name.toUpperCase()}.md`
|
|
57
76
|
});
|
|
58
77
|
}
|
|
59
78
|
try {
|
package/core/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eoasmxd/freya-core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"clean": "rm -rf dist"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@eoasmxd/freya-sdk": "^0.5.
|
|
19
|
+
"@eoasmxd/freya-sdk": "^0.5.1",
|
|
20
20
|
"ws": "^8.18.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eoasmxd/freya",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Freya - 微内核智能体系统",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"src"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@eoasmxd/freya-sdk": "^0.5.
|
|
38
|
+
"@eoasmxd/freya-sdk": "^0.5.1",
|
|
39
39
|
"ws": "^8.18.0",
|
|
40
40
|
"mysql2": "^3.11.0",
|
|
41
41
|
"qrcode": "^1.5.4"
|
|
@@ -1,39 +1,63 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { FREYA_APP, FREYA_HOME } from '../utils/paths.js';
|
|
3
|
+
import { FREYA_APP, FREYA_HOME, FREYA_WORKSPACE } from '../utils/paths.js';
|
|
4
4
|
|
|
5
5
|
export interface FreyaPrompt {
|
|
6
6
|
key: string;
|
|
7
7
|
content: string;
|
|
8
8
|
defaultPath: string;
|
|
9
|
-
|
|
9
|
+
configFileName?: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/** 提示词内存注册表,管理所有系统及插件级提示词的分类检索 */
|
|
13
13
|
export class FreyaPromptRegistry {
|
|
14
14
|
private prompts = new Map<string, FreyaPrompt>();
|
|
15
15
|
|
|
16
|
-
private
|
|
17
|
-
|
|
16
|
+
private resolveProbePaths(prompt: Omit<FreyaPrompt, 'content'>): string[] {
|
|
17
|
+
const baseName = path.basename(prompt.defaultPath);
|
|
18
|
+
const rawPaths: string[] = [];
|
|
19
|
+
|
|
20
|
+
if (prompt.configFileName) {
|
|
21
|
+
rawPaths.push(path.join(FREYA_HOME, 'config', prompt.configFileName));
|
|
22
|
+
rawPaths.push(path.join(FREYA_WORKSPACE, 'config', prompt.configFileName));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
rawPaths.push(path.join(FREYA_HOME, 'config', 'prompts', baseName));
|
|
26
|
+
rawPaths.push(path.join(FREYA_WORKSPACE, 'config', 'prompts', baseName));
|
|
27
|
+
rawPaths.push(prompt.defaultPath);
|
|
28
|
+
|
|
29
|
+
const candidates: string[] = [];
|
|
30
|
+
const seen = new Set<string>();
|
|
31
|
+
for (const rawPath of rawPaths) {
|
|
32
|
+
const normalized = path.resolve(rawPath);
|
|
33
|
+
if (!seen.has(normalized)) {
|
|
34
|
+
seen.add(normalized);
|
|
35
|
+
candidates.push(normalized);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return candidates;
|
|
18
39
|
}
|
|
19
40
|
|
|
20
|
-
/**
|
|
41
|
+
/** 注册提示词元数据声明并执行三层级联探针载入 */
|
|
21
42
|
async register(prompt: Omit<FreyaPrompt, 'content'>): Promise<void> {
|
|
22
|
-
const
|
|
43
|
+
const probePaths = this.resolveProbePaths(prompt);
|
|
23
44
|
let content = '';
|
|
24
|
-
|
|
45
|
+
|
|
46
|
+
for (const filePath of probePaths) {
|
|
25
47
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
48
|
+
const text = await fs.readFile(filePath, 'utf-8');
|
|
49
|
+
if (text.trim().length > 0) {
|
|
50
|
+
content = text;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
} catch {}
|
|
54
|
+
}
|
|
31
55
|
|
|
32
56
|
this.prompts.set(prompt.key, {
|
|
33
57
|
key: prompt.key,
|
|
34
58
|
content: content.trim(),
|
|
35
59
|
defaultPath: prompt.defaultPath,
|
|
36
|
-
|
|
60
|
+
configFileName: prompt.configFileName
|
|
37
61
|
});
|
|
38
62
|
}
|
|
39
63
|
|
|
@@ -58,7 +82,7 @@ export class FreyaPromptRegistry {
|
|
|
58
82
|
return this.prompts;
|
|
59
83
|
}
|
|
60
84
|
|
|
61
|
-
/**
|
|
85
|
+
/** 扫描并装载所有内核提示词 */
|
|
62
86
|
async loadKernelPrompts(): Promise<void> {
|
|
63
87
|
const defaultDirPath = path.join(FREYA_APP, 'config', 'prompts');
|
|
64
88
|
try {
|
|
@@ -67,7 +91,7 @@ export class FreyaPromptRegistry {
|
|
|
67
91
|
await this.register({
|
|
68
92
|
key: `core.prompt.${name}`,
|
|
69
93
|
defaultPath: path.join(defaultDirPath, `core.prompt.${name}.md`),
|
|
70
|
-
|
|
94
|
+
configFileName: `${name.toUpperCase()}.md`
|
|
71
95
|
});
|
|
72
96
|
}
|
|
73
97
|
|