@becrafter/prompt-manager 0.0.16 → 0.0.19
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/IFLOW.md +175 -0
- package/README.md +66 -80
- package/app/desktop/assets/icons/icon.icns +0 -0
- package/app/desktop/assets/icons/icon.ico +0 -0
- package/app/desktop/assets/icons/icon_1024x1024.png +0 -0
- package/app/desktop/assets/icons/icon_128x128.png +0 -0
- package/app/desktop/assets/icons/icon_16x16.png +0 -0
- package/app/desktop/assets/icons/icon_24x24.png +0 -0
- package/app/desktop/assets/icons/icon_256x256.png +0 -0
- package/app/desktop/assets/icons/icon_32x32.png +0 -0
- package/app/desktop/assets/icons/icon_48x48.png +0 -0
- package/app/desktop/assets/icons/icon_512x512.png +0 -0
- package/app/desktop/assets/icons/icon_64x64.png +0 -0
- package/app/desktop/assets/icons/icon_96x96.png +0 -0
- package/app/desktop/assets/templates/about.html +147 -0
- package/app/desktop/main.js +178 -460
- package/app/desktop/package-lock.json +1150 -412
- package/app/desktop/package.json +54 -11
- package/app/desktop/preload.js +7 -0
- package/app/desktop/src/core/error-handler.js +108 -0
- package/app/desktop/src/core/event-emitter.js +84 -0
- package/app/desktop/src/core/logger.js +108 -0
- package/app/desktop/src/core/state-manager.js +125 -0
- package/app/desktop/src/services/module-loader.js +193 -0
- package/app/desktop/src/services/runtime-manager.js +152 -0
- package/app/desktop/src/services/service-manager.js +169 -0
- package/app/desktop/src/services/update-manager.js +268 -0
- package/app/desktop/src/ui/about-dialog-manager.js +208 -0
- package/app/desktop/src/ui/tray-manager.js +202 -0
- package/app/desktop/src/utils/icon-manager.js +141 -0
- package/app/desktop/src/utils/path-utils.js +58 -0
- package/app/desktop/src/utils/resource-paths.js +72 -0
- package/app/desktop/src/utils/template-renderer.js +284 -0
- package/app/desktop/src/utils/version-utils.js +59 -0
- package/examples/prompts/engineer/engineer-professional.yaml +92 -0
- package/examples/prompts/engineer/laowang-engineer.yaml +132 -0
- package/examples/prompts/engineer/nekomata-engineer.yaml +123 -0
- package/examples/prompts/engineer/ojousama-engineer.yaml +124 -0
- package/examples/prompts/workflow/sixstep-workflow.yaml +192 -0
- package/package.json +10 -3
- package/packages/admin-ui/admin.html +2 -2
- package/packages/resources/tools/filesystem/filesystem.tool.js +184 -0
- package/packages/resources/tools/index.js +16 -0
- package/packages/server/api/admin.routes.js +450 -0
- package/packages/server/api/open.routes.js +89 -0
- package/packages/server/app.js +163 -0
- package/packages/server/mcp/mcp.handler.js +265 -0
- package/packages/server/mcp/mcp.server.js +181 -0
- package/packages/server/mcp/toolx.handler.js +131 -0
- package/packages/server/middlewares/auth.middleware.js +34 -0
- package/packages/server/server.js +42 -908
- package/packages/server/{manager.js → services/manager.js} +13 -5
- package/packages/server/{config.js → utils/config.js} +27 -27
- package/packages/server/utils/util.js +356 -0
- package/scripts/build-icons.js +105 -0
- package/scripts/icns-builder/package.json +12 -0
- package/packages/server/mcp.js +0 -234
- package/packages/server/mcpManager.js +0 -205
- /package/app/desktop/assets/{icon.png → icons/icon.png} +0 -0
- /package/packages/server/{logger.js → utils/logger.js} +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// 导入自定义模块
|
|
2
|
+
import { config } from '../utils/config.js';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
4
|
+
import { util } from '../utils/util.js';
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import YAML from 'yaml';
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
// 处理 toolx 工具调用
|
|
14
|
+
export async function handleToolX(args) {
|
|
15
|
+
const { yaml: yamlInput } = args;
|
|
16
|
+
|
|
17
|
+
if (!yamlInput) {
|
|
18
|
+
throw new Error("缺少必需参数: yaml");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
// Auto-correct common AI mistakes
|
|
23
|
+
let yamlContent = yamlInput.trim();
|
|
24
|
+
|
|
25
|
+
// Case 1: Just a plain URL string like "tool://filesystem" or "@tool://filesystem"
|
|
26
|
+
if (yamlContent.match(/^@?tool:\/\/[\w-]+$/)) {
|
|
27
|
+
const toolName = yamlContent.replace(/^@?tool:\/\//, '');
|
|
28
|
+
yamlContent = `tool: tool://${toolName}\nmode: execute`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Case 2: Handle escaped backslashes and quotes: tool: \"@tool://xxx\"
|
|
32
|
+
// This happens when AI generates YAML in a JSON string
|
|
33
|
+
yamlContent = yamlContent.replace(/\\\\/g, '\\').replace(/\\"/g, '"');
|
|
34
|
+
|
|
35
|
+
// Case 3: Remove @ prefix from tool URLs: @tool://xxx -> tool://xxx
|
|
36
|
+
yamlContent = yamlContent.replace(/@tool:\/\//g, 'tool://');
|
|
37
|
+
|
|
38
|
+
// Case 4: Remove quotes around tool URLs: tool: "tool://xxx" -> tool: tool://xxx
|
|
39
|
+
yamlContent = yamlContent.replace(/(tool|toolUrl|url):\s*"(tool:\/\/[^\"]+)"/g, '$1: $2');
|
|
40
|
+
|
|
41
|
+
// YAML → JSON conversion
|
|
42
|
+
const configObj = YAML.parse(yamlContent);
|
|
43
|
+
|
|
44
|
+
// Normalize field names (support aliases for AI-friendliness)
|
|
45
|
+
// Priority: tool > toolUrl > url
|
|
46
|
+
const toolIdentifier = configObj.tool || configObj.toolUrl || configObj.url;
|
|
47
|
+
|
|
48
|
+
// Priority: mode > operation
|
|
49
|
+
const operationMode = configObj.mode || configObj.operation;
|
|
50
|
+
|
|
51
|
+
// Validate required fields
|
|
52
|
+
if (!toolIdentifier) {
|
|
53
|
+
throw new Error('Missing required field: tool\nExample: tool: tool://filesystem\nAliases supported: tool / toolUrl / url');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Validate URL format
|
|
57
|
+
if (!toolIdentifier.startsWith('tool://')) {
|
|
58
|
+
throw new Error(`Invalid tool format: ${toolIdentifier}\nMust start with tool://`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Get tool name
|
|
62
|
+
const toolName = toolIdentifier.replace('tool://', '');
|
|
63
|
+
|
|
64
|
+
// Check if tool exists in our local tools directory
|
|
65
|
+
const rootDir = path.join(__dirname, '..', '..', '..');
|
|
66
|
+
const toolsDir = path.join(rootDir, 'packages', 'resources', 'tools');
|
|
67
|
+
const toolPath = path.join(toolsDir, `${toolName}`, `${toolName}.tool.js`);
|
|
68
|
+
|
|
69
|
+
if (!fs.existsSync(toolPath)) {
|
|
70
|
+
// List available tools
|
|
71
|
+
const availableTools = await fs.readdir(toolsDir);
|
|
72
|
+
const toolList = availableTools.filter(file => file.endsWith('.js')).map(file => path.basename(file, '.js'));
|
|
73
|
+
|
|
74
|
+
throw new Error(`Tool '${toolName}' not found\nAvailable tools: ${toolList.join(', ')}\nTools are located in: ${toolsDir}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Load and execute the tool
|
|
78
|
+
const toolModule = await import(toolPath);
|
|
79
|
+
const toolFunction = toolModule.default || toolModule.execute || toolModule.run;
|
|
80
|
+
|
|
81
|
+
if (typeof toolFunction !== 'function') {
|
|
82
|
+
throw new Error(`Tool '${toolName}' does not export a valid function`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Execute the tool with provided parameters
|
|
86
|
+
const result = await toolFunction(configObj.parameters || {}, operationMode || 'execute');
|
|
87
|
+
|
|
88
|
+
// 如果是 manual 模式,直接返回 Markdown 格式的手册
|
|
89
|
+
if (operationMode === 'manual') {
|
|
90
|
+
return {
|
|
91
|
+
content: [
|
|
92
|
+
{
|
|
93
|
+
type: "text",
|
|
94
|
+
text: result
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 其他模式返回 JSON 格式的结果
|
|
101
|
+
return {
|
|
102
|
+
content: [
|
|
103
|
+
{
|
|
104
|
+
type: "text",
|
|
105
|
+
text: JSON.stringify({
|
|
106
|
+
success: true,
|
|
107
|
+
tool: toolName,
|
|
108
|
+
mode: operationMode || 'execute',
|
|
109
|
+
result: result
|
|
110
|
+
}, null, 2)
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
};
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// YAML parsing errors
|
|
116
|
+
if (error.name === 'YAMLException') {
|
|
117
|
+
// Check for multiline string issues
|
|
118
|
+
if (error.message.includes('bad indentation') || error.message.includes('mapping entry')) {
|
|
119
|
+
throw new Error(`YAML format error: ${error.message}\n\nMultiline content requires | symbol, example:\ncontent: |\n First line\n Second line\n\nNote: Newline after |, indent content with 2 spaces`);
|
|
120
|
+
}
|
|
121
|
+
throw new Error(`YAML format error: ${error.message}\nCheck indentation (use spaces) and syntax`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Tool not found
|
|
125
|
+
if (error.message?.includes('Tool not found')) {
|
|
126
|
+
throw new Error(error.message);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { config } from '../utils/config.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 管理员API中间件
|
|
5
|
+
* @param {*} req
|
|
6
|
+
* @param {*} res
|
|
7
|
+
* @param {*} next
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function adminAuthMiddleware(req, res, next) {
|
|
11
|
+
// 检查是否启用了管理员功能
|
|
12
|
+
if (!config.adminEnable) {
|
|
13
|
+
return res.status(404).json({ error: 'Admin功能未启用' });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 检查Authorization请求头是否存在且格式正确
|
|
17
|
+
const authHeader = req.headers.authorization;
|
|
18
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
19
|
+
return res.status(401).json({ error: '未提供认证令牌' });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 提取Bearer token
|
|
23
|
+
const token = authHeader.substring(7);
|
|
24
|
+
|
|
25
|
+
// 验证令牌是否在配置的管理员列表中
|
|
26
|
+
const admin = config.admins.find(a => a.token === token);
|
|
27
|
+
if (!admin) {
|
|
28
|
+
return res.status(401).json({ error: '无效的认证令牌' });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 将管理员信息附加到请求对象,供后续中间件使用
|
|
32
|
+
req.admin = admin;
|
|
33
|
+
next();
|
|
34
|
+
}
|