@becrafter/prompt-manager 0.1.2 → 0.1.8

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 (110) hide show
  1. package/README.md +304 -121
  2. package/app/cli/commands/start.js +28 -4
  3. package/app/cli/support/argv.js +6 -0
  4. package/env.example +32 -0
  5. package/package.json +36 -6
  6. package/packages/server/api/admin.routes.js +409 -1
  7. package/packages/server/api/open.routes.js +7 -2
  8. package/packages/server/api/tool.routes.js +479 -0
  9. package/packages/server/app.js +97 -25
  10. package/packages/server/configs/models/built-in/bigmodel.yaml +6 -0
  11. package/packages/server/configs/models/providers.yaml +50 -0
  12. package/packages/server/configs/templates/built-in/general-iteration.yaml +60 -0
  13. package/packages/server/configs/templates/built-in/general-optimize.yaml +63 -0
  14. package/packages/server/configs/templates/built-in/output-format-optimize.yaml +95 -0
  15. package/packages/server/mcp/heartbeat-patch.js +73 -0
  16. package/packages/server/mcp/mcp.server.js +63 -314
  17. package/packages/server/mcp/prompt.handler.js +26 -0
  18. package/packages/server/mcp/thinking-toolkit.handler.js +380 -0
  19. package/packages/server/package.json +35 -3
  20. package/packages/server/server.js +114 -12
  21. package/packages/server/services/TerminalService.js +498 -0
  22. package/packages/server/services/WebSocketService.js +484 -0
  23. package/packages/server/services/manager.js +38 -7
  24. package/packages/server/services/model.service.js +473 -0
  25. package/packages/server/services/optimization.service.js +457 -0
  26. package/packages/server/services/template.service.js +333 -0
  27. package/packages/server/toolm/tool-description-generator-optimized.service.js +5 -2
  28. package/packages/server/toolm/tool-sync.service.js +47 -3
  29. package/packages/server/utils/config.js +8 -1
  30. package/packages/server/utils/port-checker.js +63 -0
  31. package/packages/server/utils/util.js +27 -0
  32. package/IFLOW.md +0 -175
  33. package/app/desktop/assets/app.1.png +0 -0
  34. package/app/desktop/assets/app.png +0 -0
  35. package/app/desktop/assets/icons/icon.icns +0 -0
  36. package/app/desktop/assets/icons/icon.ico +0 -0
  37. package/app/desktop/assets/icons/icon.png +0 -0
  38. package/app/desktop/assets/icons/tray.png +0 -0
  39. package/app/desktop/assets/templates/about.html +0 -147
  40. package/app/desktop/assets/tray.1.png +0 -0
  41. package/app/desktop/assets/tray.png +0 -0
  42. package/app/desktop/main.js +0 -241
  43. package/app/desktop/package-lock.json +0 -5026
  44. package/app/desktop/package.json +0 -100
  45. package/app/desktop/preload.js +0 -7
  46. package/app/desktop/src/core/error-handler.js +0 -108
  47. package/app/desktop/src/core/event-emitter.js +0 -84
  48. package/app/desktop/src/core/logger.js +0 -108
  49. package/app/desktop/src/core/state-manager.js +0 -125
  50. package/app/desktop/src/services/module-loader.js +0 -214
  51. package/app/desktop/src/services/runtime-manager.js +0 -301
  52. package/app/desktop/src/services/service-manager.js +0 -169
  53. package/app/desktop/src/services/update-manager.js +0 -267
  54. package/app/desktop/src/ui/about-dialog-manager.js +0 -208
  55. package/app/desktop/src/ui/admin-window-manager.js +0 -757
  56. package/app/desktop/src/ui/splash-manager.js +0 -253
  57. package/app/desktop/src/ui/tray-manager.js +0 -186
  58. package/app/desktop/src/utils/icon-manager.js +0 -133
  59. package/app/desktop/src/utils/path-utils.js +0 -58
  60. package/app/desktop/src/utils/resource-paths.js +0 -49
  61. package/app/desktop/src/utils/resource-sync.js +0 -260
  62. package/app/desktop/src/utils/runtime-sync.js +0 -241
  63. package/app/desktop/src/utils/template-renderer.js +0 -284
  64. package/app/desktop/src/utils/version-utils.js +0 -59
  65. package/examples/prompts/developer/code-review.yaml +0 -32
  66. package/examples/prompts/developer/code_refactoring.yaml +0 -31
  67. package/examples/prompts/developer/doc-generator.yaml +0 -36
  68. package/examples/prompts/developer/error-code-fixer.yaml +0 -35
  69. package/examples/prompts/engineer/engineer-professional.yaml +0 -92
  70. package/examples/prompts/engineer/laowang-engineer.yaml +0 -132
  71. package/examples/prompts/engineer/nekomata-engineer.yaml +0 -123
  72. package/examples/prompts/engineer/ojousama-engineer.yaml +0 -124
  73. package/examples/prompts/generator/gen_3d_edu_webpage_html.yaml +0 -117
  74. package/examples/prompts/generator/gen_3d_webpage_html.yaml +0 -75
  75. package/examples/prompts/generator/gen_bento_grid_html.yaml +0 -112
  76. package/examples/prompts/generator/gen_html_web_page.yaml +0 -88
  77. package/examples/prompts/generator/gen_knowledge_card_html.yaml +0 -83
  78. package/examples/prompts/generator/gen_magazine_card_html.yaml +0 -82
  79. package/examples/prompts/generator/gen_mimeng_headline_title.yaml +0 -71
  80. package/examples/prompts/generator/gen_podcast_script.yaml +0 -69
  81. package/examples/prompts/generator/gen_prd_prototype_html.yaml +0 -175
  82. package/examples/prompts/generator/gen_summarize.yaml +0 -157
  83. package/examples/prompts/generator/gen_title.yaml +0 -119
  84. package/examples/prompts/generator/others/api_documentation.yaml +0 -32
  85. package/examples/prompts/generator/others/build_mcp_server.yaml +0 -26
  86. package/examples/prompts/generator/others/project_architecture.yaml +0 -31
  87. package/examples/prompts/generator/others/test_case_generator.yaml +0 -30
  88. package/examples/prompts/generator/others/writing_assistant.yaml +0 -72
  89. package/examples/prompts/recommend/human_3-0_growth_diagnostic_coach_prompt.yaml +0 -105
  90. package/examples/prompts/workflow/sixstep-workflow.yaml +0 -192
  91. package/packages/admin-ui/.babelrc +0 -3
  92. package/packages/admin-ui/admin.html +0 -412
  93. package/packages/admin-ui/css/codemirror-theme_xq-light.css +0 -43
  94. package/packages/admin-ui/css/codemirror.css +0 -344
  95. package/packages/admin-ui/css/main.css +0 -2592
  96. package/packages/admin-ui/css/recommended-prompts.css +0 -610
  97. package/packages/admin-ui/package-lock.json +0 -6973
  98. package/packages/admin-ui/package.json +0 -36
  99. package/packages/admin-ui/src/codemirror.js +0 -53
  100. package/packages/admin-ui/src/index.js +0 -3188
  101. package/packages/admin-ui/webpack.config.js +0 -76
  102. package/packages/server/toolm/test-tools.js +0 -264
  103. package/scripts/build-icons.js +0 -135
  104. package/scripts/build.sh +0 -57
  105. package/scripts/postinstall.js +0 -34
  106. package/scripts/surge/CNAME +0 -1
  107. package/scripts/surge/README.md +0 -47
  108. package/scripts/surge/package-lock.json +0 -34
  109. package/scripts/surge/package.json +0 -20
  110. package/scripts/surge/sync-to-surge.js +0 -151
package/README.md CHANGED
@@ -2,110 +2,294 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40becrafter%2Fprompt-manager.svg)](https://www.npmjs.com/package/@becrafter/prompt-manager)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D22.20.0-brightgreen)]()
5
6
 
6
- > **一个提示词管理工具,帮你把常用的 AI 提示词整理成库,随时调用。**
7
+ > 🚀 **让AI提示词管理变得简单而强大** - 支持MCP协议、AI优化、多界面管理的企业级提示词管理平台
7
8
 
8
- ## 这是什么?
9
+ ## ✨ 核心特性
9
10
 
10
- 想象一下,你经常用 AI 写代码、做翻译、写文案...每次都要重新输入类似的提示词,很麻烦。
11
+ ### 🎯 AI提示词管理
12
+ - 📝 **模板化管理** - 将常用提示词保存为可复用的模板
13
+ - 🔍 **智能搜索** - 支持关键词和语义搜索,快速找到所需提示词
14
+ - 📁 **分组组织** - 支持文件夹分组,便于分类管理
15
+ - 🔧 **参数化支持** - 支持变量替换,让提示词更灵活
11
16
 
12
- **Prompt Manager 就是帮你管理这些提示词的工具:**
17
+ ### 🤖 AI增强功能
18
+ - ⚡ **AI优化** - 使用AI自动优化你的提示词质量
19
+ - 🔄 **迭代改进** - 支持多轮迭代优化,持续提升效果
20
+ - 📊 **会话跟踪** - 跟踪优化过程中的迭代状态
13
21
 
14
- - 📝 把提示词保存成模板,随时调用
15
- - 🔍 快速搜索你需要的提示词
16
- - 🌐 通过网页界面管理,简单直观
17
- - 💻 也可以作为服务运行,让其他程序调用
22
+ ### 🔌 开放生态
23
+ - 🔗 **MCP协议** - 完全兼容Model Context Protocol标准
24
+ - 🛠️ **ToolM系统** - 内置工具沙箱,支持扩展自定义工具
25
+ - 🌐 **API驱动** - 提供完整的REST API,支持程序化调用
26
+ - 📡 **流式传输** - 支持HTTP流式传输,实时获取结果
18
27
 
19
- **简单说:就像收藏夹,但专门用来管理 AI 提示词。**
28
+ ### 💻 多界面支持
29
+ - 🖥️ **桌面应用** - 开箱即用的Electron桌面应用
30
+ - 🌐 **Web管理** - 现代化的Web管理界面
31
+ - 💻 **命令行** - 强大的CLI工具,支持脚本集成
20
32
 
21
- ## 快速开始
33
+ ## 🚀 快速开始
22
34
 
23
- ### 方式一:命令行使用(适合技术人员)
35
+ ### 方式一:桌面应用(推荐)
24
36
 
25
37
  ```bash
26
- # 1. 安装
38
+ # 1. 下载并安装桌面应用
39
+ npm run desktop:build
40
+
41
+ # 2. 双击运行安装包
42
+ # 3. 点击系统托盘图标开始使用
43
+ ```
44
+
45
+ **效果展示:**
46
+ ![演示动画](./docs/assets/demo.gif)
47
+
48
+
49
+ ![](./docs/assets/1.png)
50
+ ![](./docs/assets/2.png)
51
+ ![](./docs/assets/3.png)
52
+ ![](./docs/assets/4.png)
53
+ ![](./docs/assets/5.png)
54
+ ![](./docs/assets/6.png)
55
+ ![](./docs/assets/7.png)
56
+ ![](./docs/assets/8.png)
57
+
58
+
59
+
60
+ ### 方式二:命令行运行
61
+
62
+ #### 安装 CLI 工具
63
+
64
+ ```bash
65
+ # 全局安装(推荐)
27
66
  npm install -g @becrafter/prompt-manager
28
67
 
29
- # 2. 启动服务
68
+ # 或本地安装
69
+ npm install @becrafter/prompt-manager
70
+ npx @becrafter/prompt-manager
71
+ ```
72
+
73
+ #### 基本使用
74
+
75
+ ```bash
76
+ # 启动服务(默认端口 5621)
30
77
  prompt-manager
31
78
 
32
- # 3. 打开浏览器访问
79
+ # 指定端口和提示词目录
80
+ prompt-manager --prompts-dir ./my-prompts --port 8080
81
+
82
+ # 查看帮助信息
83
+ prompt-manager --help
84
+ ```
85
+
86
+ #### CLI 参数说明
87
+
88
+ ```bash
89
+ # 核心参数
90
+ -p, --prompts-dir <目录> 指定 prompts 文件所在目录
91
+ -P, --port <端口> 指定服务器端口 (默认: 5621)
92
+ -h, --help 显示帮助信息
93
+
94
+ # 示例
95
+ prompt-manager --prompts-dir ./examples/prompts
96
+ prompt-manager -p /path/to/prompts -P 3000
97
+ ```
98
+
99
+ ### 方式三:开发环境
100
+
101
+ ```bash
102
+ # 克隆项目
103
+ git clone https://github.com/BeCrafter/prompt-manager.git
104
+ cd prompt-manager
105
+
106
+ # 安装依赖
107
+ npm install
108
+
109
+ # 启动开发服务器
110
+ npm run dev:all
111
+
112
+ # 访问管理界面
33
113
  # http://localhost:5621/admin
34
114
  ```
35
115
 
36
- 就这么简单!服务启动后,打开浏览器就能看到管理界面。
116
+ ## 🎨 使用场景
117
+
118
+ ### 👥 团队协作
119
+ - **共享提示词库** - 团队成员共享高质量提示词模板
120
+ - **标准化流程** - 统一团队的AI使用规范和最佳实践
121
+ - **知识传承** - 新成员快速上手,避免重复造轮子
122
+
123
+ ### 🤖 AI开发者
124
+ - **提示词优化** - 使用AI自动改进提示词效果
125
+ - **版本管理** - 跟踪提示词的演进历史
126
+ - **效果对比** - A/B测试不同版本的提示词效果
127
+
128
+ ### 🛠️ 程序集成
129
+ - **API调用** - 通过REST API集成到现有系统中
130
+ - **MCP协议** - 与支持MCP的AI客户端无缝集成
131
+ - **自动化流程** - 在CI/CD流程中自动调用提示词
132
+
133
+ ## 📋 核心功能
134
+
135
+ ### 提示词管理
136
+ - ✅ 创建和编辑提示词模板
137
+ - ✅ 支持YAML格式配置
138
+ - ✅ 参数化变量替换
139
+ - ✅ 分组和标签管理
140
+ - ✅ 启用/禁用控制
141
+
142
+ ### AI优化服务
143
+ - ✅ 多模型支持(OpenAI、Google等)
144
+ - ✅ 流式优化输出
145
+ - ✅ 迭代优化模式
146
+ - ✅ 优化历史记录
147
+
148
+ ### 工具生态
149
+ - ✅ 内置常用工具(文件操作、PDF读取等)
150
+ - ✅ 沙箱安全执行
151
+ - ✅ 自定义工具扩展
152
+ - ✅ 工具市场机制
153
+
154
+ #### 🛡️ 工具沙箱机制
155
+
156
+ Prompt Manager 采用创新的工具沙箱机制,确保工具安全可控:
157
+
158
+ **工作原理:**
159
+ 1. **系统工具存储** - 内置工具位于 `packages/resources/tools/`
160
+ 2. **沙箱环境同步** - 首次运行时自动复制到 `~/.prompt-manager/toolbox/`
161
+ 3. **隔离执行** - 每个工具在独立沙箱目录中运行
162
+ 4. **权限控制** - 自动生成 package.json 管理工具权限
163
+
164
+ **内置工具列表:**
165
+ - **filesystem** - 文件系统操作(读写文件、目录管理)
166
+ - **file-reader** - 高级文件读取(支持多种格式)
167
+ - **pdf-reader** - PDF 文档解析和内容提取
168
+ - **chrome-devtools** - 浏览器自动化和网页抓取
169
+ - **playwright** - 现代网页自动化测试
170
+ - **ollama-remote** - 本地 AI 模型集成
171
+ - **todolist** - 任务管理和待办事项
172
+
173
+ **自定义工具开发:**
174
+ ```javascript
175
+ // 工具结构示例
176
+ export default {
177
+ getMetadata() {
178
+ return {
179
+ name: 'my-tool',
180
+ description: '我的自定义工具',
181
+ version: '1.0.0'
182
+ };
183
+ },
184
+
185
+ getSchema() {
186
+ return {
187
+ type: 'object',
188
+ properties: {
189
+ input: { type: 'string' }
190
+ }
191
+ };
192
+ },
193
+
194
+ async execute({ input }) {
195
+ // 工具逻辑
196
+ return { result: `处理结果: ${input}` };
197
+ }
198
+ };
199
+ ```
200
+
201
+ ### 界面体验
202
+ - ✅ 现代化Web界面
203
+ - ✅ 原生桌面应用
204
+ - ✅ 命令行工具
205
+ - ✅ 响应式设计
37
206
 
38
- ### 方式二:桌面应用(适合所有人)
207
+ ## 🛠️ 环境要求
39
208
 
40
- 下载桌面应用,双击运行,点击菜单栏图标就能管理提示词。
209
+ ### 系统要求
41
210
 
42
- > 💡 桌面应用正在开发中,敬请期待
211
+ #### 通用要求
212
+ - **Node.js**: v22.20.0+ (推荐使用 nvm 管理版本)
213
+ - **操作系统**: macOS, Windows, Linux
214
+ - **内存**: 至少 512MB 可用内存
215
+ - **磁盘空间**: 至少 200MB 可用空间(包含工具沙箱)
43
216
 
44
- ## 怎么用?
217
+ #### NPM 包使用要求
218
+ - **Node.js**: v22.20.0+ (必须版本)
219
+ - **网络**: 需要网络连接(用于 AI 模型调用)
220
+ - **权限**: 需要写权限创建用户配置目录
221
+ - **原生模块**: node-pty (会自动编译)
45
222
 
46
- ### 1. 创建提示词
223
+ #### 开发环境额外要求
224
+ - **Git**: 用于代码管理
225
+ - **npm**: v8.0.0+ (随 Node.js 安装)
226
+ - **Python**: v3.7+ (用于原生模块编译)
47
227
 
48
- 在管理界面点击"新建",输入提示词内容:
228
+ ### 环境检查
49
229
 
50
- ```yaml
51
- name: 代码审查
52
- description: 帮我审查代码质量
53
- messages:
54
- - role: user
55
- content:
56
- text: |
57
- 请审查以下代码,找出潜在问题:
58
-
59
- {{code}}
230
+ 项目提供了便捷的环境检查脚本:
231
+
232
+ ```bash
233
+ # 自动检查开发环境
234
+ npm run check:env
235
+
236
+ # 或手动检查
237
+ node --version # 应显示 v22.x.x
238
+ npm --version # 检查 npm 版本
60
239
  ```
61
240
 
62
- ### 2. 使用提示词
241
+ ### 常见问题
63
242
 
64
- 保存后,你可以:
65
- - 在管理界面直接使用
66
- - 通过 API 调用(适合程序员)
67
- - 在支持 MCP 协议的 AI 客户端中使用
243
+ #### Node.js 版本问题
244
+ ```bash
245
+ # 使用 nvm 切换版本
246
+ nvm install 22
247
+ nvm use 22
68
248
 
69
- ### 3. 管理提示词
249
+ # 或从官网下载 v22.20.0
250
+ # https://nodejs.org/
251
+ ```
70
252
 
71
- - 📁 按文件夹分类整理
72
- - 🔍 快速搜索
73
- - ✏️ 随时编辑
74
- - 🗑️ 删除不需要的
253
+ #### 依赖编译问题
254
+ ```bash
255
+ # 修复 node-pty 编译问题
256
+ npm run fix:pty
257
+ ```
75
258
 
76
- ## 常见使用场景
259
+ #### NPM 包使用问题
77
260
 
78
- **场景 1:团队共享提示词**
79
- - 把团队常用的提示词整理在一起
80
- - 新成员直接使用,不用重复写
261
+ **Q: 安装后提示权限错误?**
262
+ ```bash
263
+ # 使用管理员权限安装(macOS/Linux)
264
+ sudo npm install -g @becrafter/prompt-manager
81
265
 
82
- **场景 2:个人知识库**
83
- - 把好用的提示词保存下来
84
- - 按项目、按类型分类管理
266
+ # 或使用 nvm 管理的 Node.js
267
+ nvm use 22
268
+ npm install -g @becrafter/prompt-manager
269
+ ```
85
270
 
86
- **场景 3:集成到其他工具**
87
- - 作为服务运行
88
- - 其他程序通过 API 调用你的提示词库
271
+ **Q: 启动时报错 "node-pty module not available"?**
272
+ ```bash
273
+ # 重新编译原生模块
274
+ npm rebuild node-pty
89
275
 
90
- ## 提示词格式
276
+ # 或在项目目录中运行
277
+ cd /usr/local/lib/node_modules/@becrafter/prompt-manager
278
+ npm rebuild node-pty
279
+ ```
91
280
 
92
- 提示词用 YAML 格式保存,很简单:
281
+ **Q: 如何查看工具沙箱目录?**
282
+ ```bash
283
+ # 查看沙箱目录内容
284
+ ls -la ~/.prompt-manager/toolbox/
93
285
 
94
- ```yaml
95
- name: 提示词名称
96
- description: 简短描述
97
- messages:
98
- - role: user
99
- content:
100
- text: 提示词内容,可以用 {{变量名}} 来占位
101
- arguments:
102
- - name: 变量名
103
- description: 变量说明
104
- type: string
105
- enabled: true
286
+ # 查看工具日志
287
+ ls -la ~/.prompt-manager/toolbox/*/logs/
106
288
  ```
107
289
 
108
- **示例:代码审查提示词**
290
+ ## 📝 提示词格式
291
+
292
+ Prompt Manager 使用简洁的 YAML 格式定义提示词:
109
293
 
110
294
  ```yaml
111
295
  name: code-review
@@ -115,61 +299,57 @@ messages:
115
299
  content:
116
300
  text: |
117
301
  请审查这段 {{language}} 代码:
118
-
302
+
119
303
  ```{{language}}
120
304
  {{code}}
121
305
  ```
122
-
123
- 请指出:
124
- 1. 潜在问题
125
- 2. 改进建议
306
+
307
+ 请指出潜在问题和改进建议
126
308
  arguments:
127
309
  - name: language
128
310
  description: 编程语言
129
311
  type: string
312
+ required: true
130
313
  - name: code
131
314
  description: 要审查的代码
132
315
  type: string
316
+ required: true
133
317
  enabled: true
134
318
  ```
135
319
 
136
- ## 配置说明
320
+ ### 参数支持
321
+ - **变量替换**: 使用 `{{变量名}}` 语法
322
+ - **类型支持**: string, number, boolean
323
+ - **可选参数**: 设置 `required: false`
137
324
 
138
- ### 命令行参数
325
+ ### 分组管理
326
+ - **文件夹分组**: 将提示词放在子目录中自动分组
327
+ - **分组元数据**: 在 `.group.json` 中定义分组信息
328
+
329
+ ## ⚙️ 配置和部署
139
330
 
331
+ ### 命令行参数
140
332
  ```bash
141
- prompt-manager --port 6000 # 指定端口
333
+ prompt-manager --port 5621 # 指定端口
142
334
  prompt-manager --prompts-dir ./prompts # 指定提示词目录
143
335
  ```
144
336
 
145
337
  ### 环境变量
146
-
147
- 创建 `.env` 文件(可选):
148
-
149
338
  ```env
150
339
  SERVER_PORT=5621
151
340
  ADMIN_USERNAME=admin
152
- ADMIN_PASSWORD=你的密码
341
+ ADMIN_PASSWORD=your_password
342
+ LOG_LEVEL=info
153
343
  ```
154
344
 
155
- ## 常见问题
156
-
157
- **Q: 提示词保存在哪里?**
158
- A: 默认保存在 `~/.prompt-manager/prompts` 目录
159
-
160
- **Q: 可以多人使用吗?**
161
- A: 可以,把提示词目录共享,或者部署为服务供团队使用
162
-
163
- **Q: 支持哪些 AI 客户端?**
164
- A: 支持 MCP 协议的客户端都可以使用(如 Claude Desktop)
345
+ ### 存储位置
346
+ - **提示词**: `~/.prompt-manager/prompts`
347
+ - **配置**: `~/.prompt-manager/.env`
348
+ - **日志**: `~/Library/Application Support/@becrafter/prompt-desktop/`
165
349
 
166
- **Q: 需要编程基础吗?**
167
- A: 使用网页界面不需要,但作为服务运行需要基本的命令行知识
168
-
169
- ## 技术细节(可选看)
350
+ ## 🔧 开发者指南
170
351
 
171
352
  ### 作为库使用
172
-
173
353
  ```javascript
174
354
  import { startServer } from '@becrafter/prompt-manager-core';
175
355
 
@@ -181,43 +361,46 @@ await startServer({
181
361
  });
182
362
  ```
183
363
 
184
- ### API 接口
185
-
186
- - `GET /prompts` - 获取提示词列表
187
- - `GET /api/prompts/:name` - 获取单个提示词
188
- - `POST /api/prompts` - 创建/更新提示词
189
- - `POST /process` - 处理提示词(支持参数替换)
364
+ ### 开发环境
365
+ ```bash
366
+ git clone https://github.com/BeCrafter/prompt-manager.git
367
+ cd prompt-manager
368
+ npm install
369
+ npm run dev:all # 启动所有服务
370
+ ```
190
371
 
191
- ### MCP 协议支持
372
+ ## 📡 API 概览
192
373
 
193
- 支持以下 MCP 工具:
194
- - `search_prompts` - 搜索提示词
195
- - `get_prompt` - 获取提示词
196
- - `reload_prompts` - 重新加载
374
+ ### 管理 API (需要认证)
375
+ - `GET /adminapi/prompts` - 获取提示词列表
376
+ - `POST /adminapi/prompts` - 创建/更新提示词
377
+ - `GET /adminapi/optimization/models` - 获取AI模型列表
378
+ - `POST /adminapi/prompts/optimize` - AI优化提示词
197
379
 
198
- ## 开发
380
+ ### 公开 API (无需认证)
381
+ - `GET /openapi/prompts` - 获取启用的提示词
382
+ - `POST /openapi/process` - 处理提示词
199
383
 
200
- ```bash
201
- # 克隆项目
202
- git clone https://github.com/BeCrafter/prompt-server.git
203
- cd prompt-server
384
+ ### MCP 协议支持
385
+ - `search_prompts` - 搜索提示词
386
+ - `get_prompt` - 获取提示词详情
387
+ - `reload_prompts` - 重新加载提示词
204
388
 
205
- # 安装依赖
206
- npm install
389
+ ## 🤝 贡献指南
207
390
 
208
- # 启动开发服务器
209
- npm run dev
210
- ```
391
+ 我们欢迎各种形式的贡献!
211
392
 
212
- ## 许可证
393
+ 1. **Bug 报告** - [提交 Issue](https://github.com/BeCrafter/prompt-manager/issues)
394
+ 2. **功能建议** - 在 Discussions 中分享你的想法
395
+ 3. **代码贡献** - Fork 并提交 Pull Request
396
+ 4. **文档改进** - 帮助完善文档和示例
213
397
 
214
- MIT License
398
+ ## 📄 许可证
215
399
 
216
- ## 相关链接
400
+ MIT License - 详见 [LICENSE](LICENSE) 文件
217
401
 
218
- - [npm 包](https://www.npmjs.com/package/@becrafter/prompt-manager)
219
- - [问题反馈](https://github.com/BeCrafter/prompt-server/issues)
402
+ ## 🙏 致谢
220
403
 
221
- ---
404
+ 感谢所有贡献者和用户,让这个项目变得更好!
222
405
 
223
- **Made with ❤️ by BeCrafter**
406
+ **Made with ❤️ by BeCrafter Team**
@@ -1,15 +1,39 @@
1
- import { normalizeArgv } from '../support/argv.js';
2
1
  import { registerSignalHandlers } from '../support/signals.js';
3
2
 
3
+ // 简单的 CLI 参数解析
4
+ function parseCLIArgs(args) {
5
+ const options = {};
6
+ for (let i = 0; i < args.length; i++) {
7
+ const arg = args[i];
8
+ if (arg === '--prompts-dir' || arg === '-p') {
9
+ options.promptsDir = args[i + 1];
10
+ i++;
11
+ } else if (arg === '--port' || arg === '-P') {
12
+ options.port = parseInt(args[i + 1]);
13
+ i++;
14
+ } else if (arg === '--help' || arg === '-h') {
15
+ options.help = true;
16
+ } else if (arg === '--version' || arg === '-v') {
17
+ options.version = true;
18
+ }
19
+ }
20
+ return options;
21
+ }
22
+
4
23
  export async function startCommand(rawArgs, options = {}) {
5
- const { scriptPath } = options;
6
- process.argv = normalizeArgv(rawArgs, scriptPath);
24
+ const cliOptions = parseCLIArgs(rawArgs);
25
+
26
+ // 如果请求帮助,显示 CLI 帮助
27
+ if (cliOptions.help) {
28
+ console.log(`Prompt Server CLI\n\n用法:\n prompt-manager [command] [options]\n\n可用命令:\n start 启动服务 (默认)\n run 启动服务 (同 start)\n\n选项:\n -p, --prompts-dir <目录> 指定 prompts 文件所在目录\n -P, --port <端口> 指定服务器端口 (默认: 5621)\n -h, --help 显示此帮助信息\n\n示例:\n prompt-manager --port 6000\n prompt-manager start --prompts-dir ./examples/prompts`);
29
+ return;
30
+ }
7
31
 
8
32
  const { startServer, stopServer, getServerState } = await import('../../../packages/server/server.js');
9
33
 
10
34
  registerSignalHandlers(stopServer);
11
35
 
12
- await startServer();
36
+ await startServer(cliOptions);
13
37
 
14
38
  const state = getServerState();
15
39
  console.log(`Prompt Server 已启动:${state.address}`);
@@ -2,6 +2,12 @@ import { fileURLToPath } from 'url';
2
2
 
3
3
  export function normalizeArgv(rawArgs, scriptPathOverride) {
4
4
  const execPath = process.execPath || 'node';
5
+
6
+ // 如果是全局安装的包,不需要修改 argv,因为 process.argv 已经正确设置
7
+ if (process.env.npm_config_global || process.env.npm_config_prefix) {
8
+ return [execPath, process.argv[1], ...(rawArgs || [])];
9
+ }
10
+
5
11
  const scriptPath = scriptPathOverride ?? fileURLToPath(new URL('../index.js', import.meta.url));
6
12
  return [execPath, scriptPath, ...(rawArgs || [])];
7
13
  }
package/env.example ADDED
@@ -0,0 +1,32 @@
1
+ # 环境变量配置示例
2
+ # 复制此文件为 .env 并根据需要修改
3
+ SERVER_PORT=5621
4
+
5
+ # Prompts目录路径 (默认: ~/.prompt-manager/prompts,可通过命令行覆盖)
6
+ PROMPTS_DIR=$HOME/.prompt-manager/prompts
7
+
8
+ # MCP服务器配置
9
+ MCP_SERVER_NAME=prompt-manager
10
+ MCP_SERVER_VERSION=0.1.8
11
+
12
+ # 日志级别 (error, warn, info, debug)
13
+ LOG_LEVEL=info
14
+
15
+ # 最大prompt数量限制
16
+ MAX_PROMPTS=1000
17
+
18
+ # 管理员功能配置
19
+
20
+ # 是否启用管理员功能
21
+ ADMIN_ENABLE=true
22
+ # 是否需要登录认证
23
+ ADMIN_REQUIRE_AUTH=true
24
+ # 管理员用户名
25
+ ADMIN_USERNAME=admin
26
+ # 理员密码
27
+ ADMIN_PASSWORD=admin
28
+ # 管理员路径
29
+ ADMIN_PATH=/admin
30
+
31
+ # 模型 API Key 配置
32
+ OPENROUTER_API_KEY=your_openrouter_api_key_here