@becrafter/prompt-manager 0.1.2 → 0.1.9
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/README.md +304 -121
- package/app/cli/commands/start.js +65 -4
- package/app/cli/support/argv.js +6 -0
- package/env.example +32 -0
- package/package.json +36 -7
- package/packages/server/api/admin.routes.js +409 -1
- package/packages/server/api/open.routes.js +7 -2
- package/packages/server/api/tool.routes.js +479 -0
- package/packages/server/app.js +97 -25
- package/packages/server/configs/models/built-in/bigmodel.yaml +6 -0
- package/packages/server/configs/models/providers.yaml +50 -0
- package/packages/server/configs/templates/built-in/general-iteration.yaml +60 -0
- package/packages/server/configs/templates/built-in/general-optimize.yaml +63 -0
- package/packages/server/configs/templates/built-in/output-format-optimize.yaml +95 -0
- package/packages/server/mcp/heartbeat-patch.js +73 -0
- package/packages/server/mcp/mcp.server.js +63 -314
- package/packages/server/mcp/prompt.handler.js +26 -0
- package/packages/server/mcp/thinking-toolkit.handler.js +380 -0
- package/packages/server/package.json +35 -3
- package/packages/server/server.js +114 -12
- package/packages/server/services/TerminalService.js +498 -0
- package/packages/server/services/WebSocketService.js +484 -0
- package/packages/server/services/manager.js +38 -7
- package/packages/server/services/model.service.js +473 -0
- package/packages/server/services/optimization.service.js +457 -0
- package/packages/server/services/template.service.js +333 -0
- package/packages/server/toolm/tool-description-generator-optimized.service.js +5 -2
- package/packages/server/toolm/tool-sync.service.js +47 -3
- package/packages/server/utils/config.js +8 -1
- package/packages/server/utils/port-checker.js +63 -0
- package/packages/server/utils/util.js +27 -0
- package/IFLOW.md +0 -175
- package/app/desktop/assets/app.1.png +0 -0
- package/app/desktop/assets/app.png +0 -0
- package/app/desktop/assets/icons/icon.icns +0 -0
- package/app/desktop/assets/icons/icon.ico +0 -0
- package/app/desktop/assets/icons/icon.png +0 -0
- package/app/desktop/assets/icons/tray.png +0 -0
- package/app/desktop/assets/templates/about.html +0 -147
- package/app/desktop/assets/tray.1.png +0 -0
- package/app/desktop/assets/tray.png +0 -0
- package/app/desktop/main.js +0 -241
- package/app/desktop/package-lock.json +0 -5026
- package/app/desktop/package.json +0 -100
- package/app/desktop/preload.js +0 -7
- package/app/desktop/src/core/error-handler.js +0 -108
- package/app/desktop/src/core/event-emitter.js +0 -84
- package/app/desktop/src/core/logger.js +0 -108
- package/app/desktop/src/core/state-manager.js +0 -125
- package/app/desktop/src/services/module-loader.js +0 -214
- package/app/desktop/src/services/runtime-manager.js +0 -301
- package/app/desktop/src/services/service-manager.js +0 -169
- package/app/desktop/src/services/update-manager.js +0 -267
- package/app/desktop/src/ui/about-dialog-manager.js +0 -208
- package/app/desktop/src/ui/admin-window-manager.js +0 -757
- package/app/desktop/src/ui/splash-manager.js +0 -253
- package/app/desktop/src/ui/tray-manager.js +0 -186
- package/app/desktop/src/utils/icon-manager.js +0 -133
- package/app/desktop/src/utils/path-utils.js +0 -58
- package/app/desktop/src/utils/resource-paths.js +0 -49
- package/app/desktop/src/utils/resource-sync.js +0 -260
- package/app/desktop/src/utils/runtime-sync.js +0 -241
- package/app/desktop/src/utils/template-renderer.js +0 -284
- package/app/desktop/src/utils/version-utils.js +0 -59
- package/examples/prompts/developer/code-review.yaml +0 -32
- package/examples/prompts/developer/code_refactoring.yaml +0 -31
- package/examples/prompts/developer/doc-generator.yaml +0 -36
- package/examples/prompts/developer/error-code-fixer.yaml +0 -35
- package/examples/prompts/engineer/engineer-professional.yaml +0 -92
- package/examples/prompts/engineer/laowang-engineer.yaml +0 -132
- package/examples/prompts/engineer/nekomata-engineer.yaml +0 -123
- package/examples/prompts/engineer/ojousama-engineer.yaml +0 -124
- package/examples/prompts/generator/gen_3d_edu_webpage_html.yaml +0 -117
- package/examples/prompts/generator/gen_3d_webpage_html.yaml +0 -75
- package/examples/prompts/generator/gen_bento_grid_html.yaml +0 -112
- package/examples/prompts/generator/gen_html_web_page.yaml +0 -88
- package/examples/prompts/generator/gen_knowledge_card_html.yaml +0 -83
- package/examples/prompts/generator/gen_magazine_card_html.yaml +0 -82
- package/examples/prompts/generator/gen_mimeng_headline_title.yaml +0 -71
- package/examples/prompts/generator/gen_podcast_script.yaml +0 -69
- package/examples/prompts/generator/gen_prd_prototype_html.yaml +0 -175
- package/examples/prompts/generator/gen_summarize.yaml +0 -157
- package/examples/prompts/generator/gen_title.yaml +0 -119
- package/examples/prompts/generator/others/api_documentation.yaml +0 -32
- package/examples/prompts/generator/others/build_mcp_server.yaml +0 -26
- package/examples/prompts/generator/others/project_architecture.yaml +0 -31
- package/examples/prompts/generator/others/test_case_generator.yaml +0 -30
- package/examples/prompts/generator/others/writing_assistant.yaml +0 -72
- package/examples/prompts/recommend/human_3-0_growth_diagnostic_coach_prompt.yaml +0 -105
- package/examples/prompts/workflow/sixstep-workflow.yaml +0 -192
- package/packages/admin-ui/.babelrc +0 -3
- package/packages/admin-ui/admin.html +0 -412
- package/packages/admin-ui/css/codemirror-theme_xq-light.css +0 -43
- package/packages/admin-ui/css/codemirror.css +0 -344
- package/packages/admin-ui/css/main.css +0 -2592
- package/packages/admin-ui/css/recommended-prompts.css +0 -610
- package/packages/admin-ui/package-lock.json +0 -6973
- package/packages/admin-ui/package.json +0 -36
- package/packages/admin-ui/src/codemirror.js +0 -53
- package/packages/admin-ui/src/index.js +0 -3188
- package/packages/admin-ui/webpack.config.js +0 -76
- package/packages/server/toolm/test-tools.js +0 -264
- package/scripts/build-icons.js +0 -135
- package/scripts/build.sh +0 -57
- package/scripts/postinstall.js +0 -34
- package/scripts/surge/CNAME +0 -1
- package/scripts/surge/README.md +0 -47
- package/scripts/surge/package-lock.json +0 -34
- package/scripts/surge/package.json +0 -20
- package/scripts/surge/sync-to-surge.js +0 -151
package/IFLOW.md
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# Prompt Manager 项目概述
|
|
2
|
-
|
|
3
|
-
## 项目简介
|
|
4
|
-
|
|
5
|
-
Prompt Manager 是一个基于 MCP(Model Context Protocol)协议的 Prompt 管理服务。它支持 HTTP 流式传输、提供 Web 管理界面和桌面应用,能够将静态提示词模板转换为可通过 API 调用的动态服务。
|
|
6
|
-
|
|
7
|
-
核心特性包括:
|
|
8
|
-
- 完全兼容模型上下文协议(MCP)
|
|
9
|
-
- 基于 StreamableHTTP 协议优化的 HTTP 流式传输
|
|
10
|
-
- 自动发现子目录中的 prompt 文件
|
|
11
|
-
- 支持命令行参数和环境变量配置
|
|
12
|
-
- 内置 Electron 菜单应用,可一键启动/停止服务
|
|
13
|
-
- 提供 Web 管理界面,方便创建、编辑和管理提示词
|
|
14
|
-
|
|
15
|
-
## 技术栈
|
|
16
|
-
|
|
17
|
-
- **后端**: Node.js (>=18.0.0), Express.js
|
|
18
|
-
- **前端**: 内置管理界面使用原生 JavaScript 和 Codemirror
|
|
19
|
-
- **协议**: MCP (Model Context Protocol)
|
|
20
|
-
- **桌面应用**: Electron
|
|
21
|
-
- **包管理**: npm/pnpm
|
|
22
|
-
|
|
23
|
-
## 项目结构
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
prompt-manager/
|
|
27
|
-
├── app/
|
|
28
|
-
│ ├── cli/ # 命令行命令分发与共享工具
|
|
29
|
-
│ └── desktop/ # Electron 菜单应用
|
|
30
|
-
├── packages/
|
|
31
|
-
│ ├── admin-ui/ # 内置管理后台静态资源
|
|
32
|
-
│ └── server/ # 服务端核心逻辑
|
|
33
|
-
├── examples/
|
|
34
|
-
│ └── prompts/ # 随包示例提示词(首次启动会同步到 ~/.prompt-manager/prompts)
|
|
35
|
-
├── scripts/ # 安装/维护脚本(如 env 同步)
|
|
36
|
-
├── bin/ # 可执行入口
|
|
37
|
-
└── package.json
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## 构建和运行
|
|
41
|
-
|
|
42
|
-
### 安装依赖
|
|
43
|
-
|
|
44
|
-
在项目根目录运行:
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
npm install
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### 启动开发服务器
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
# 启动服务端开发服务器
|
|
54
|
-
npm run dev
|
|
55
|
-
|
|
56
|
-
# 启动桌面应用开发环境
|
|
57
|
-
npm run desktop:dev
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 构建桌面应用
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
# 构建桌面应用安装包
|
|
64
|
-
npm run desktop:build
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### 命令行使用
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
# 使用默认配置启动
|
|
71
|
-
prompt-manager
|
|
72
|
-
|
|
73
|
-
# 指定提示词目录
|
|
74
|
-
prompt-manager --prompts-dir ./my-prompts
|
|
75
|
-
|
|
76
|
-
# 指定端口
|
|
77
|
-
prompt-manager --port 5621
|
|
78
|
-
|
|
79
|
-
# 显式使用 start/run 命令
|
|
80
|
-
prompt-manager start --port 6000
|
|
81
|
-
prompt-manager run --prompts-dir ./examples/prompts
|
|
82
|
-
|
|
83
|
-
# 获取帮助/版本信息
|
|
84
|
-
prompt-manager --help
|
|
85
|
-
prompt-manager --version
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## 开发约定
|
|
89
|
-
|
|
90
|
-
1. **代码风格**: 项目使用 ES6 模块系统,遵循标准的 JavaScript 编码规范。
|
|
91
|
-
2. **目录结构**:
|
|
92
|
-
- `app/` 目录包含客户端相关代码(CLI 和桌面应用)
|
|
93
|
-
- `packages/` 目录包含服务端核心逻辑和管理界面
|
|
94
|
-
- `examples/` 目录包含示例提示词文件
|
|
95
|
-
3. **配置管理**: 支持通过命令行参数、环境变量和配置文件进行配置。
|
|
96
|
-
4. **日志记录**: 使用自定义 logger 模块进行日志记录。
|
|
97
|
-
5. **错误处理**: 统一的错误处理机制,关键操作都有适当的错误捕获和处理。
|
|
98
|
-
|
|
99
|
-
## API 接口
|
|
100
|
-
|
|
101
|
-
### MCP 协议接口
|
|
102
|
-
|
|
103
|
-
服务器实现了 MCP 协议,支持以下工具:
|
|
104
|
-
|
|
105
|
-
- `search_prompts`: 搜索提示词
|
|
106
|
-
- `get_prompt`: 获取指定提示词的完整内容
|
|
107
|
-
- `reload_prompts`: 重新加载所有提示词(暂未启用)
|
|
108
|
-
|
|
109
|
-
### Web 管理接口
|
|
110
|
-
|
|
111
|
-
1. **获取提示词列表**
|
|
112
|
-
```
|
|
113
|
-
GET /prompts[?search=关键词]
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
2. **获取单个提示词详情**
|
|
117
|
-
```
|
|
118
|
-
GET /api/prompts/:name[?path=文件路径]
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
3. **创建/更新提示词**
|
|
122
|
-
```
|
|
123
|
-
POST /api/prompts
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
4. **删除提示词**
|
|
127
|
-
```
|
|
128
|
-
DELETE /api/prompts/:name[?path=文件路径]
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
5. **切换提示词启用状态**
|
|
132
|
-
```
|
|
133
|
-
POST /api/prompts/:name/toggle[?path=文件路径]
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
6. **处理提示词**
|
|
137
|
-
```
|
|
138
|
-
POST /process
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
7. **分组管理**
|
|
142
|
-
- 获取所有分组列表: `GET /api/groups`
|
|
143
|
-
- 创建新分组: `POST /api/groups`
|
|
144
|
-
- 重命名分组: `PATCH /api/groups/rename`
|
|
145
|
-
- 更新分组启用状态: `PATCH /api/groups/status`
|
|
146
|
-
- 删除分组: `DELETE /api/groups?path=分组路径`
|
|
147
|
-
|
|
148
|
-
## 桌面应用
|
|
149
|
-
|
|
150
|
-
位于 `app/desktop` 目录,使用 Electron 构建的菜单栏应用,提供以下功能:
|
|
151
|
-
|
|
152
|
-
- 启/停服务
|
|
153
|
-
- 复制服务地址
|
|
154
|
-
- 打开管理后台
|
|
155
|
-
- 检查更新
|
|
156
|
-
- 关于服务信息
|
|
157
|
-
|
|
158
|
-
## 提示词格式
|
|
159
|
-
|
|
160
|
-
提示词文件使用 YAML 格式,需要包含以下基本结构:
|
|
161
|
-
|
|
162
|
-
```yaml
|
|
163
|
-
name: prompt-name
|
|
164
|
-
description: 提示词描述
|
|
165
|
-
messages:
|
|
166
|
-
- role: user
|
|
167
|
-
content:
|
|
168
|
-
text: 提示词内容,支持 {{参数名}} 格式的参数替换
|
|
169
|
-
arguments:
|
|
170
|
-
- name: 参数名
|
|
171
|
-
description: 参数描述
|
|
172
|
-
type: string|number|boolean
|
|
173
|
-
required: true|false
|
|
174
|
-
enabled: true|false # 是否启用该提示词
|
|
175
|
-
```
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title>关于 Prompt Manager</title>
|
|
6
|
-
<style>
|
|
7
|
-
/* 支持纵向滚动但隐藏滚动条 */
|
|
8
|
-
body {
|
|
9
|
-
margin: 0;
|
|
10
|
-
padding: 0;
|
|
11
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
12
|
-
background: linear-gradient(135deg, #ffffff 0%, #ffffff 100%);
|
|
13
|
-
color: #333;
|
|
14
|
-
min-height: 100vh;
|
|
15
|
-
display: flex;
|
|
16
|
-
flex-direction: column;
|
|
17
|
-
align-items: center;
|
|
18
|
-
justify-content: center;
|
|
19
|
-
/* 支持纵向滚动 */
|
|
20
|
-
overflow-x: hidden;
|
|
21
|
-
overflow-y: auto;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/* 针对WebKit浏览器隐藏滚动条 */
|
|
25
|
-
body::-webkit-scrollbar {
|
|
26
|
-
display: none;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/* 针对Firefox浏览器隐藏滚动条 */
|
|
30
|
-
body {
|
|
31
|
-
scrollbar-width: none;
|
|
32
|
-
-ms-overflow-style: none;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.container {
|
|
36
|
-
background: white;
|
|
37
|
-
border-radius: 12px;
|
|
38
|
-
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
|
|
39
|
-
padding: 30px;
|
|
40
|
-
width: 320px;
|
|
41
|
-
text-align: center;
|
|
42
|
-
transition: transform 0.3s ease;
|
|
43
|
-
/* 防止容器内容溢出 */
|
|
44
|
-
max-width: 100%;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.container:hover {
|
|
48
|
-
transform: translateY(-2px);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.logo {
|
|
52
|
-
width: 64px;
|
|
53
|
-
height: 64px;
|
|
54
|
-
/* background: linear-gradient(135deg, #dcdbdb 0%, #dcdbdb 100%); */
|
|
55
|
-
border-radius: 6px;
|
|
56
|
-
border: 1px solid #ccc;
|
|
57
|
-
margin: 0 auto 15px;
|
|
58
|
-
display: flex;
|
|
59
|
-
align-items: center;
|
|
60
|
-
justify-content: center;
|
|
61
|
-
font-size: 28px;
|
|
62
|
-
color: white;
|
|
63
|
-
font-weight: bold;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.version-info {
|
|
67
|
-
background: #f8f9fa;
|
|
68
|
-
border-radius: 8px;
|
|
69
|
-
padding: 15px;
|
|
70
|
-
margin-bottom: 20px;
|
|
71
|
-
text-align: left;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.version-item {
|
|
75
|
-
display: flex;
|
|
76
|
-
justify-content: space-between;
|
|
77
|
-
margin-bottom: 8px;
|
|
78
|
-
font-size: 14px;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.version-item:last-child {
|
|
82
|
-
margin-bottom: 0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.label {
|
|
86
|
-
color: #7f8c8d;
|
|
87
|
-
font-weight: 500;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.value {
|
|
91
|
-
color: #2c3e50;
|
|
92
|
-
font-weight: 500;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.notification {
|
|
96
|
-
background: #e3f2fd;
|
|
97
|
-
border-left: 4px solid #2196f3;
|
|
98
|
-
padding: 12px;
|
|
99
|
-
border-radius: 0 8px 8px 0;
|
|
100
|
-
margin: 15px 0;
|
|
101
|
-
text-align: left;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.notification-title {
|
|
105
|
-
font-weight: 600;
|
|
106
|
-
color: #1976d2;
|
|
107
|
-
margin: 0 0 5px 0;
|
|
108
|
-
font-size: 13px;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.notification-content {
|
|
112
|
-
font-size: 12px;
|
|
113
|
-
color: #555;
|
|
114
|
-
margin: 0;
|
|
115
|
-
}
|
|
116
|
-
</style>
|
|
117
|
-
</head>
|
|
118
|
-
<body>
|
|
119
|
-
<div class="container">
|
|
120
|
-
<div class="logo">
|
|
121
|
-
<img src="data:image/png;base64,{{logoData}}" alt="Prompt Server Logo" width="64" height="64">
|
|
122
|
-
</div>
|
|
123
|
-
|
|
124
|
-
<div class="version-info">
|
|
125
|
-
<div class="version-item">
|
|
126
|
-
<span class="label">服务版本:</span>
|
|
127
|
-
<span class="value">{{version}}</span>
|
|
128
|
-
</div>
|
|
129
|
-
<div class="version-item">
|
|
130
|
-
<span class="label">Electron:</span>
|
|
131
|
-
<span class="value">{{electronVersion}}</span>
|
|
132
|
-
</div>
|
|
133
|
-
<div class="version-item">
|
|
134
|
-
<span class="label">Node.js:</span>
|
|
135
|
-
<span class="value">{{nodeVersion}}</span>
|
|
136
|
-
</div>
|
|
137
|
-
</div>
|
|
138
|
-
|
|
139
|
-
{{#if debugLogEnabled}}
|
|
140
|
-
<div class="notification">
|
|
141
|
-
<div class="notification-title">调试日志已开启</div>
|
|
142
|
-
<div class="notification-content">日志文件路径: {{logFilePath}}</div>
|
|
143
|
-
</div>
|
|
144
|
-
{{/if}}
|
|
145
|
-
</div>
|
|
146
|
-
</body>
|
|
147
|
-
</html>
|
|
Binary file
|
|
Binary file
|
package/app/desktop/main.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 应用主入口
|
|
3
|
-
* 重构后的主程序,遵循SRP、KISS、DRY、YAGNI原则
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { app, BrowserWindow, ipcMain } = require('electron');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
|
|
9
|
-
// 导入管理器模块
|
|
10
|
-
const AppState = require('./src/core/state-manager');
|
|
11
|
-
const Logger = require('./src/core/logger');
|
|
12
|
-
const ErrorHandler = require('./src/core/error-handler');
|
|
13
|
-
const RuntimeManager = require('./src/services/runtime-manager');
|
|
14
|
-
const ModuleLoader = require('./src/services/module-loader');
|
|
15
|
-
const ServiceManager = require('./src/services/service-manager');
|
|
16
|
-
const TrayManager = require('./src/ui/tray-manager');
|
|
17
|
-
const UpdateManager = require('./src/services/update-manager');
|
|
18
|
-
const AboutDialogManager = require('./src/ui/about-dialog-manager');
|
|
19
|
-
const SplashManager = require('./src/ui/splash-manager');
|
|
20
|
-
const IconManager = require('./src/utils/icon-manager');
|
|
21
|
-
const RuntimeSync = require('./src/utils/runtime-sync');
|
|
22
|
-
|
|
23
|
-
class PromptManagerApp {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.stateManager = new AppState();
|
|
26
|
-
this.logger = new Logger({ debugEnabled: false });
|
|
27
|
-
this.errorHandler = new ErrorHandler(this.logger);
|
|
28
|
-
this.runtimeManager = new RuntimeManager(this.logger, this.errorHandler);
|
|
29
|
-
this.moduleLoader = new ModuleLoader(this.logger, this.errorHandler);
|
|
30
|
-
this.iconManager = new IconManager();
|
|
31
|
-
this.serviceManager = new ServiceManager(this.logger, this.errorHandler, this.moduleLoader);
|
|
32
|
-
this.updateManager = new UpdateManager(this.logger, this.errorHandler, this.runtimeManager);
|
|
33
|
-
this.aboutDialogManager = new AboutDialogManager(this.logger, this.runtimeManager, this.iconManager);
|
|
34
|
-
this.trayManager = new TrayManager(this.logger, this.errorHandler, this.iconManager);
|
|
35
|
-
this.splashManager = new SplashManager(this.logger, this.iconManager);
|
|
36
|
-
|
|
37
|
-
this.isInitialized = false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async initialize() {
|
|
41
|
-
if (this.isInitialized) return;
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
this.logger.info('Initializing Prompt Manager Desktop Application');
|
|
45
|
-
|
|
46
|
-
// 显示启动画面
|
|
47
|
-
await this.splashManager.showSplash();
|
|
48
|
-
this.splashManager.updateStatus('正在初始化...', 20);
|
|
49
|
-
|
|
50
|
-
// 同步环境配置
|
|
51
|
-
await RuntimeSync.syncRuntime();
|
|
52
|
-
this.splashManager.updateStatus('正在同步工具箱...', 35);
|
|
53
|
-
|
|
54
|
-
// 初始化日志系统
|
|
55
|
-
await this.logger.initialize();
|
|
56
|
-
|
|
57
|
-
// 设置应用菜单
|
|
58
|
-
this.setupApplicationMenu();
|
|
59
|
-
|
|
60
|
-
// 初始化系统托盘
|
|
61
|
-
this.splashManager.updateStatus('正在启动托盘服务...', 60);
|
|
62
|
-
await this.trayManager.initialize(this.stateManager);
|
|
63
|
-
|
|
64
|
-
// 设置事件监听
|
|
65
|
-
this.setupEventListeners();
|
|
66
|
-
|
|
67
|
-
// 确保运行时环境
|
|
68
|
-
this.splashManager.updateStatus('正在准备运行时环境...', 70);
|
|
69
|
-
const serverRoot = await this.runtimeManager.ensureRuntimeEnvironment();
|
|
70
|
-
this.stateManager.set('runtimeRoot', serverRoot);
|
|
71
|
-
|
|
72
|
-
// 启动服务
|
|
73
|
-
this.splashManager.updateStatus('正在启动核心服务...', 80);
|
|
74
|
-
await this.startService();
|
|
75
|
-
|
|
76
|
-
this.isInitialized = true;
|
|
77
|
-
this.logger.info('Application initialized successfully');
|
|
78
|
-
|
|
79
|
-
// 关闭启动画面
|
|
80
|
-
this.splashManager.updateStatus('准备就绪...', 100);
|
|
81
|
-
setTimeout(() => {
|
|
82
|
-
this.splashManager.closeSplash();
|
|
83
|
-
}, 500); // 短暂延迟以显示完成状态
|
|
84
|
-
|
|
85
|
-
} catch (error) {
|
|
86
|
-
this.logger.error('Application initialization failed', error);
|
|
87
|
-
|
|
88
|
-
// 关闭启动画面
|
|
89
|
-
this.splashManager.closeSplash();
|
|
90
|
-
|
|
91
|
-
this.errorHandler.handleError('APP_INIT_FAILED', error, {
|
|
92
|
-
logFilePath: this.logger.getLogFilePath()
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
setupApplicationMenu() {
|
|
100
|
-
if (process.platform === 'darwin') {
|
|
101
|
-
app.dock.hide();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 隐藏默认应用菜单
|
|
105
|
-
const { Menu } = require('electron');
|
|
106
|
-
Menu.setApplicationMenu(null);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
setupEventListeners() {
|
|
110
|
-
// 托盘事件
|
|
111
|
-
this.trayManager.on('service-start-requested', () => this.startService());
|
|
112
|
-
this.trayManager.on('service-stop-requested', () => this.stopService());
|
|
113
|
-
this.trayManager.on('update-check-requested', () => this.checkForUpdates());
|
|
114
|
-
this.trayManager.on('about-dialog-requested', () => this.showAboutDialog());
|
|
115
|
-
this.trayManager.on('quit-requested', () => this.quitApplication());
|
|
116
|
-
|
|
117
|
-
// 服务管理器事件
|
|
118
|
-
this.serviceManager.on('status-update', () => this.trayManager.updateMenu());
|
|
119
|
-
this.serviceManager.on('restart-requested', () => this.restartApplication());
|
|
120
|
-
|
|
121
|
-
// IPC事件
|
|
122
|
-
ipcMain.on('about-window-click', (event, data) => {
|
|
123
|
-
this.aboutDialogManager.handleAboutWindowClick(data);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// 应用事件
|
|
127
|
-
app.on('window-all-closed', (event) => {
|
|
128
|
-
event.preventDefault(); // 防止应用退出
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
app.on('before-quit', async (event) => {
|
|
132
|
-
if (this.stateManager.get('isQuitting')) return;
|
|
133
|
-
|
|
134
|
-
event.preventDefault();
|
|
135
|
-
await this.quitApplication();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
app.on('activate', () => {
|
|
139
|
-
if (!this.trayManager.tray) {
|
|
140
|
-
this.trayManager.initialize(this.stateManager);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async startService() {
|
|
146
|
-
const serverRoot = this.stateManager.get('runtimeRoot');
|
|
147
|
-
if (!serverRoot) {
|
|
148
|
-
this.logger.error('Cannot start service: runtime root not set');
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return await this.serviceManager.startService(serverRoot, this.stateManager);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async stopService() {
|
|
156
|
-
return await this.serviceManager.stopService(this.stateManager);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async checkForUpdates() {
|
|
160
|
-
try {
|
|
161
|
-
await this.updateManager.checkForUpdates();
|
|
162
|
-
} catch (error) {
|
|
163
|
-
this.logger.error('Update check failed', error);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
showAboutDialog() {
|
|
168
|
-
this.aboutDialogManager.showAboutDialog();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
handleAboutWindowClick(data) {
|
|
172
|
-
// 委托给AboutDialogManager处理
|
|
173
|
-
this.aboutDialogManager.handleAboutWindowClick(data);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async restartApplication() {
|
|
177
|
-
this.logger.info('Restarting application');
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
await this.stopService();
|
|
181
|
-
app.relaunch();
|
|
182
|
-
app.exit(0);
|
|
183
|
-
} catch (error) {
|
|
184
|
-
this.logger.error('Failed to restart application', error);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async quitApplication() {
|
|
189
|
-
this.logger.info('Quitting application');
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
this.stateManager.set('isQuitting', true);
|
|
193
|
-
|
|
194
|
-
// 关闭启动画面
|
|
195
|
-
await this.splashManager.closeSplash();
|
|
196
|
-
|
|
197
|
-
// 停止服务
|
|
198
|
-
await this.stopService();
|
|
199
|
-
|
|
200
|
-
// 清理资源
|
|
201
|
-
await this.aboutDialogManager.closeAboutDialog();
|
|
202
|
-
|
|
203
|
-
this.trayManager.destroy();
|
|
204
|
-
await this.logger.close();
|
|
205
|
-
await this.runtimeManager.cleanup();
|
|
206
|
-
|
|
207
|
-
app.quit();
|
|
208
|
-
} catch (error) {
|
|
209
|
-
this.logger.error('Error during application shutdown', error);
|
|
210
|
-
app.quit(); // 强制退出
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// 应用启动
|
|
216
|
-
const promptManagerApp = new PromptManagerApp();
|
|
217
|
-
|
|
218
|
-
app.whenReady().then(async () => {
|
|
219
|
-
try {
|
|
220
|
-
await promptManagerApp.initialize();
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error('Failed to start application:', error);
|
|
223
|
-
app.quit();
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// 异常处理
|
|
228
|
-
process.on('uncaughtException', (error) => {
|
|
229
|
-
console.error('Uncaught Exception:', error);
|
|
230
|
-
if (promptManagerApp.logger) {
|
|
231
|
-
promptManagerApp.logger.error('Uncaught Exception', error);
|
|
232
|
-
}
|
|
233
|
-
app.quit();
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
237
|
-
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
238
|
-
if (promptManagerApp.logger) {
|
|
239
|
-
promptManagerApp.logger.error('Unhandled Rejection', reason);
|
|
240
|
-
}
|
|
241
|
-
});
|