@becrafter/prompt-manager 0.0.19 → 0.1.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.
Files changed (103) hide show
  1. package/README.md +145 -234
  2. package/app/desktop/assets/app.1.png +0 -0
  3. package/app/desktop/assets/app.png +0 -0
  4. package/app/desktop/assets/icons/icon.icns +0 -0
  5. package/app/desktop/assets/icons/icon.ico +0 -0
  6. package/app/desktop/assets/icons/icon.png +0 -0
  7. package/app/desktop/assets/icons/tray.png +0 -0
  8. package/app/desktop/assets/tray.1.png +0 -0
  9. package/app/desktop/assets/tray.png +0 -0
  10. package/app/desktop/main.js +27 -0
  11. package/app/desktop/package-lock.json +216 -48
  12. package/app/desktop/package.json +23 -29
  13. package/app/desktop/src/services/module-loader.js +43 -22
  14. package/app/desktop/src/services/runtime-manager.js +172 -23
  15. package/app/desktop/src/ui/admin-window-manager.js +757 -0
  16. package/app/desktop/src/ui/splash-manager.js +253 -0
  17. package/app/desktop/src/ui/tray-manager.js +8 -24
  18. package/app/desktop/src/utils/icon-manager.js +39 -47
  19. package/app/desktop/src/utils/resource-paths.js +0 -23
  20. package/app/desktop/src/utils/resource-sync.js +260 -0
  21. package/app/desktop/src/utils/runtime-sync.js +241 -0
  22. package/examples/prompts/recommend/human_3-0_growth_diagnostic_coach_prompt.yaml +105 -0
  23. package/package.json +16 -13
  24. package/packages/admin-ui/.babelrc +3 -0
  25. package/packages/admin-ui/admin.html +237 -4784
  26. package/packages/admin-ui/css/main.css +2592 -0
  27. package/packages/admin-ui/css/recommended-prompts.css +610 -0
  28. package/packages/admin-ui/package-lock.json +6981 -0
  29. package/packages/admin-ui/package.json +36 -0
  30. package/packages/admin-ui/src/codemirror.js +53 -0
  31. package/packages/admin-ui/src/index.js +3188 -0
  32. package/packages/admin-ui/webpack.config.js +76 -0
  33. package/packages/resources/tools/chrome-devtools/README.md +310 -0
  34. package/packages/resources/tools/chrome-devtools/chrome-devtools.tool.js +1703 -0
  35. package/packages/resources/tools/file-reader/README.md +289 -0
  36. package/packages/resources/tools/file-reader/file-reader.tool.js +1545 -0
  37. package/packages/resources/tools/filesystem/README.md +359 -0
  38. package/packages/resources/tools/filesystem/filesystem.tool.js +514 -160
  39. package/packages/resources/tools/ollama-remote/README.md +192 -0
  40. package/packages/resources/tools/ollama-remote/ollama-remote.tool.js +421 -0
  41. package/packages/resources/tools/pdf-reader/README.md +236 -0
  42. package/packages/resources/tools/pdf-reader/pdf-reader.tool.js +565 -0
  43. package/packages/resources/tools/playwright/README.md +306 -0
  44. package/packages/resources/tools/playwright/playwright.tool.js +1186 -0
  45. package/packages/resources/tools/todolist/README.md +394 -0
  46. package/packages/resources/tools/todolist/todolist.tool.js +1312 -0
  47. package/packages/server/README.md +142 -0
  48. package/packages/server/api/admin.routes.js +42 -11
  49. package/packages/server/api/surge.routes.js +43 -0
  50. package/packages/server/app.js +119 -14
  51. package/packages/server/index.js +39 -0
  52. package/packages/server/mcp/mcp.server.js +324 -105
  53. package/packages/server/mcp/sequential-thinking.handler.js +318 -0
  54. package/packages/server/mcp/think-plan.handler.js +274 -0
  55. package/packages/server/middlewares/auth.middleware.js +6 -0
  56. package/packages/server/package.json +51 -0
  57. package/packages/server/server.js +37 -1
  58. package/packages/server/toolm/index.js +9 -0
  59. package/packages/server/toolm/package-installer.service.js +267 -0
  60. package/packages/server/toolm/test-tools.js +264 -0
  61. package/packages/server/toolm/tool-context.service.js +334 -0
  62. package/packages/server/toolm/tool-dependency.service.js +168 -0
  63. package/packages/server/toolm/tool-description-generator-optimized.service.js +375 -0
  64. package/packages/server/toolm/tool-description-generator.service.js +312 -0
  65. package/packages/server/toolm/tool-environment.service.js +200 -0
  66. package/packages/server/toolm/tool-execution.service.js +277 -0
  67. package/packages/server/toolm/tool-loader.service.js +219 -0
  68. package/packages/server/toolm/tool-logger.service.js +223 -0
  69. package/packages/server/toolm/tool-manager.handler.js +65 -0
  70. package/packages/server/toolm/tool-manual-generator.service.js +389 -0
  71. package/packages/server/toolm/tool-mode-handlers.service.js +224 -0
  72. package/packages/server/toolm/tool-storage.service.js +111 -0
  73. package/packages/server/toolm/tool-sync.service.js +138 -0
  74. package/packages/server/toolm/tool-utils.js +20 -0
  75. package/packages/server/toolm/tool-yaml-parser.service.js +81 -0
  76. package/packages/server/toolm/validate-system.js +421 -0
  77. package/packages/server/utils/config.js +49 -5
  78. package/packages/server/utils/util.js +65 -10
  79. package/scripts/build-icons.js +99 -69
  80. package/scripts/build.sh +57 -0
  81. package/scripts/surge/CNAME +1 -0
  82. package/scripts/surge/README.md +47 -0
  83. package/scripts/surge/package-lock.json +34 -0
  84. package/scripts/surge/package.json +20 -0
  85. package/scripts/surge/sync-to-surge.js +151 -0
  86. package/app/desktop/assets/icons/icon_1024x1024.png +0 -0
  87. package/app/desktop/assets/icons/icon_128x128.png +0 -0
  88. package/app/desktop/assets/icons/icon_16x16.png +0 -0
  89. package/app/desktop/assets/icons/icon_24x24.png +0 -0
  90. package/app/desktop/assets/icons/icon_256x256.png +0 -0
  91. package/app/desktop/assets/icons/icon_32x32.png +0 -0
  92. package/app/desktop/assets/icons/icon_48x48.png +0 -0
  93. package/app/desktop/assets/icons/icon_512x512.png +0 -0
  94. package/app/desktop/assets/icons/icon_64x64.png +0 -0
  95. package/app/desktop/assets/icons/icon_96x96.png +0 -0
  96. package/packages/admin-ui/js/closebrackets.min.js +0 -8
  97. package/packages/admin-ui/js/codemirror.min.js +0 -8
  98. package/packages/admin-ui/js/js-yaml.min.js +0 -2
  99. package/packages/admin-ui/js/markdown.min.js +0 -8
  100. package/packages/resources/tools/index.js +0 -16
  101. package/packages/server/mcp/toolx.handler.js +0 -131
  102. package/scripts/icns-builder/package.json +0 -12
  103. /package/packages/server/mcp/{mcp.handler.js → prompt.handler.js} +0 -0
@@ -0,0 +1,289 @@
1
+ # File Reader Tool
2
+
3
+ 统一文件读取工具,支持本地和远程文件,自动识别文件类型并转换为模型友好格式。
4
+
5
+ ## 功能特性
6
+
7
+ 1. **统一接口** (`read_file`)
8
+ - 支持本地文件(file:// 协议或本地路径)
9
+ - 支持远程文件(http://, https://)
10
+ - 自动识别文件类型
11
+ - 智能转换为模型友好格式
12
+
13
+ 2. **文件类型支持**
14
+ - 文本文件(.txt, .md, .log 等)
15
+ - 代码文件(.js, .py, .java 等)
16
+ - 配置文件(.json, .yaml, .xml 等)
17
+ - 图片文件(.png, .jpg, .gif 等)
18
+ - 视频/音频文件(提取元信息)
19
+ - 文档文件(PDF 等,需要配合 pdf-reader 工具)
20
+
21
+ 3. **智能转换**
22
+ - 自动检测编码格式(UTF-8, GBK 等)
23
+ - JSON/YAML/XML 自动解析为对象
24
+ - 图片转换为 base64 + 描述
25
+ - 视频/音频提取元信息
26
+
27
+ 4. **链接提取**
28
+ - 支持提取文本中的嵌套链接
29
+ - 递归读取链接内容
30
+ - 防止无限递归
31
+
32
+ 5. **缓存机制**
33
+ - 自动缓存读取结果
34
+ - 可配置缓存超时时间
35
+ - 减少重复读取
36
+
37
+ ## 环境变量配置
38
+
39
+ 工具需要配置以下环境变量:
40
+
41
+ - `ALLOWED_DIRECTORIES` (可选): 允许访问的本地目录列表(JSON数组格式)
42
+ - 默认值: `["~/.prompt-manager"]`
43
+ - 示例: `["~/.prompt-manager", "/tmp"]`
44
+
45
+ - `ALLOWED_URLS` (可选): 允许访问的远程URL白名单(JSON数组格式,支持通配符)
46
+ - 默认值: `["https://*", "http://*"]`
47
+ - 示例: `["https://example.com/*", "https://*.github.com/*"]`
48
+
49
+ - `MAX_FILE_SIZE` (可选): 最大文件大小(字节),默认 `10485760` (10MB)
50
+
51
+ - `DEFAULT_TIMEOUT` (可选): 默认超时时间(毫秒),默认 `30000` (30秒)
52
+
53
+ - `DEFAULT_CACHE_TIMEOUT` (可选): 默认缓存超时时间(毫秒),默认 `600000` (10分钟)
54
+
55
+ - `MAX_RECURSION_DEPTH` (可选): 最大递归深度,默认 `3`
56
+
57
+ ## 使用方法
58
+
59
+ ### 1. 配置环境变量
60
+
61
+ ```yaml
62
+ tool: tool://file-reader
63
+ mode: configure
64
+ parameters:
65
+ ALLOWED_DIRECTORIES: '["~/.prompt-manager", "/tmp"]'
66
+ ALLOWED_URLS: '["https://*", "http://*"]'
67
+ MAX_FILE_SIZE: "10485760"
68
+ ```
69
+
70
+ ### 2. 读取本地文件
71
+
72
+ ```yaml
73
+ tool: tool://file-reader
74
+ mode: execute
75
+ parameters:
76
+ method: read_file
77
+ url: "~/.prompt-manager/config.json"
78
+ convertTo: "auto" # auto, text, json, xml, image, video, audio
79
+ encoding: "auto" # auto, utf-8, gbk, etc.
80
+ ```
81
+
82
+ ### 3. 读取远程文件
83
+
84
+ ```yaml
85
+ tool: tool://file-reader
86
+ mode: execute
87
+ parameters:
88
+ method: read_file
89
+ url: "https://example.com/data.json"
90
+ convertTo: "json"
91
+ ```
92
+
93
+ ### 4. 提取嵌套链接
94
+
95
+ ```yaml
96
+ tool: tool://file-reader
97
+ mode: execute
98
+ parameters:
99
+ method: read_file
100
+ url: "https://example.com/index.md"
101
+ extractLinks: true
102
+ maxDepth: 3
103
+ ```
104
+
105
+ ## 参数说明
106
+
107
+ ### read_file 方法
108
+
109
+ - `method` (必需): 必须为 `"read_file"`
110
+ - `url` (必需): 文件URL或路径(支持 file://, http://, https:// 或本地路径)
111
+ - `encoding` (可选): 文本文件编码(默认自动检测,支持 utf-8, gbk, gb2312等),默认 `"auto"`
112
+ - `convertTo` (可选): 转换目标格式(auto/text/json/xml/image/video/audio),默认 `"auto"`
113
+ - `includeMetadata` (可选): 是否包含文件元信息,默认 `true`
114
+ - `maxSize` (可选): 最大文件大小(字节),默认 `10485760` (10MB)
115
+ - `timeout` (可选): 远程文件下载超时时间(毫秒),默认 `30000` (30秒)
116
+ - `basePath` (可选): 基础路径(用于解析相对路径)
117
+ - `extractLinks` (可选): 是否提取并读取文本中的嵌套链接,默认 `false`
118
+ - `maxDepth` (可选): 递归读取链接的最大深度(防止无限递归),默认 `3`,范围 1-10
119
+ - `cacheTimeout` (可选): 缓存超时时间(毫秒),默认 `600000` (10分钟)
120
+ - `useCache` (可选): 是否使用缓存,默认 `true`
121
+
122
+ ## 返回格式
123
+
124
+ ### 文本文件返回
125
+
126
+ ```json
127
+ {
128
+ "success": true,
129
+ "source": {
130
+ "url": "file:///path/to/file.txt",
131
+ "resolvedUrl": "/path/to/file.txt",
132
+ "type": "local",
133
+ "path": "/path/to/file.txt"
134
+ },
135
+ "file": {
136
+ "type": "text",
137
+ "mimeType": "text/plain",
138
+ "encoding": "utf-8",
139
+ "size": 1024
140
+ },
141
+ "content": "文件内容...",
142
+ "format": "text",
143
+ "metadata": {
144
+ "detectedType": "text",
145
+ "conversion": "text_decode",
146
+ "originalSize": 1024,
147
+ "convertedSize": 1024,
148
+ "fromCache": false,
149
+ "nestedLinksCount": 0
150
+ }
151
+ }
152
+ ```
153
+
154
+ ### JSON文件返回
155
+
156
+ ```json
157
+ {
158
+ "success": true,
159
+ "source": {
160
+ "url": "https://example.com/data.json",
161
+ "resolvedUrl": "https://example.com/data.json",
162
+ "type": "remote",
163
+ "path": "https://example.com/data.json"
164
+ },
165
+ "file": {
166
+ "type": "json",
167
+ "mimeType": "application/json",
168
+ "encoding": "utf-8",
169
+ "size": 2048
170
+ },
171
+ "content": {
172
+ "key": "value"
173
+ },
174
+ "format": "json",
175
+ "metadata": {
176
+ "detectedType": "json",
177
+ "conversion": "json_parse",
178
+ "originalSize": 2048,
179
+ "convertedSize": 512,
180
+ "fromCache": false
181
+ }
182
+ }
183
+ ```
184
+
185
+ ### 图片文件返回
186
+
187
+ ```json
188
+ {
189
+ "success": true,
190
+ "file": {
191
+ "type": "image",
192
+ "mimeType": "image/png",
193
+ "size": 8192
194
+ },
195
+ "content": {
196
+ "dataUrl": "data:image/png;base64,...",
197
+ "base64": "...",
198
+ "mimeType": "image/png",
199
+ "dimensions": {
200
+ "width": 800,
201
+ "height": 600
202
+ },
203
+ "size": 8192,
204
+ "description": "图片文件,格式: image/png,大小: 8.00KB,尺寸: 800x600"
205
+ },
206
+ "format": "image"
207
+ }
208
+ ```
209
+
210
+ ## 错误处理
211
+
212
+ 工具定义了以下业务错误:
213
+
214
+ - `INVALID_URL`: 无效的URL格式
215
+ - `URL_NOT_ALLOWED`: URL不在白名单中
216
+ - `FILE_NOT_FOUND`: 文件不存在
217
+ - `FILE_TOO_LARGE`: 文件过大
218
+ - `NETWORK_ERROR`: 网络错误
219
+ - `PERMISSION_DENIED`: 权限不足
220
+ - `UNSUPPORTED_ENCODING`: 不支持的编码格式
221
+ - `PARSE_ERROR`: 文件解析失败
222
+ - `PATH_OUTSIDE_SCOPE`: 路径越权访问
223
+
224
+ ## 注意事项
225
+
226
+ 1. **服务器同步**: 新添加的工具需要重启服务器才能被加载
227
+ 2. **URL白名单**: 远程文件需要配置 `ALLOWED_URLS` 白名单
228
+ 3. **文件大小限制**: 默认最大文件大小为 10MB,可通过环境变量调整
229
+ 4. **编码检测**: 自动编码检测可能不准确,建议明确指定编码
230
+ 5. **链接提取**: 递归读取链接时注意 `maxDepth` 设置,避免无限递归
231
+ 6. **缓存机制**: 使用缓存可提高性能,但可能返回过期数据
232
+ 7. **相对路径**: 使用相对路径时需要提供 `basePath` 参数
233
+
234
+ ## 测试步骤
235
+
236
+ 1. **重启服务器**(如果服务器已在运行)
237
+
238
+ 2. **查看工具手册**
239
+ ```yaml
240
+ tool: tool://file-reader
241
+ mode: manual
242
+ ```
243
+
244
+ 3. **配置环境变量**
245
+ ```yaml
246
+ tool: tool://file-reader
247
+ mode: configure
248
+ parameters:
249
+ ALLOWED_DIRECTORIES: '["~/.prompt-manager"]'
250
+ ALLOWED_URLS: '["https://*", "http://*"]'
251
+ ```
252
+
253
+ 4. **测试读取本地文件**
254
+ ```yaml
255
+ tool: tool://file-reader
256
+ mode: execute
257
+ parameters:
258
+ method: read_file
259
+ url: "~/.prompt-manager/test.txt"
260
+ ```
261
+
262
+ 5. **测试读取远程文件**
263
+ ```yaml
264
+ tool: tool://file-reader
265
+ mode: execute
266
+ parameters:
267
+ method: read_file
268
+ url: "https://example.com/data.json"
269
+ convertTo: "json"
270
+ ```
271
+
272
+ ## 开发说明
273
+
274
+ 工具遵循 Prompt Manager 工具开发规范:
275
+
276
+ - 使用 ES6 模块格式 (`export default`)
277
+ - 实现必需方法 `execute()`
278
+ - 实现推荐方法:`getDependencies()`, `getMetadata()`, `getSchema()`, `getBusinessErrors()`
279
+ - 完整的错误处理和日志记录
280
+ - 符合工具开发指南的所有要求
281
+
282
+ ## 版本历史
283
+
284
+ - **1.0.0** (2025-01-01): 初始版本
285
+ - 实现统一文件读取接口
286
+ - 支持本地和远程文件
287
+ - 自动识别文件类型并转换
288
+ - 支持链接提取和缓存机制
289
+