@becrafter/prompt-manager 0.1.21 → 0.1.31
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/package.json +23 -23
- package/packages/resources/tools/agent-browser/README.md +640 -0
- package/packages/resources/tools/agent-browser/agent-browser.tool.js +1388 -0
- package/packages/resources/tools/thinking/README.md +324 -0
- package/packages/resources/tools/thinking/thinking.tool.js +911 -0
- package/packages/server/README.md +3 -4
- package/packages/server/api/admin.routes.js +668 -664
- package/packages/server/api/open.routes.js +68 -67
- package/packages/server/api/surge.routes.js +5 -6
- package/packages/server/api/tool.routes.js +70 -71
- package/packages/server/app.js +70 -73
- package/packages/server/configs/authors.json +40 -0
- package/packages/server/configs/models/built-in/bigmodel.yaml +6 -6
- package/packages/server/configs/models/providers.yaml +4 -4
- package/packages/server/configs/templates/built-in/general-iteration.yaml +1 -1
- package/packages/server/configs/templates/built-in/general-optimize.yaml +1 -1
- package/packages/server/configs/templates/built-in/output-format-optimize.yaml +1 -1
- package/packages/server/index.js +3 -9
- package/packages/server/mcp/heartbeat-patch.js +1 -3
- package/packages/server/mcp/mcp.server.js +64 -134
- package/packages/server/mcp/prompt.handler.js +101 -95
- package/packages/server/middlewares/auth.middleware.js +31 -31
- package/packages/server/server.js +60 -45
- package/packages/server/services/TerminalService.js +156 -70
- package/packages/server/services/WebSocketService.js +35 -34
- package/packages/server/services/author-config.service.js +199 -0
- package/packages/server/services/manager.js +66 -60
- package/packages/server/services/model.service.js +5 -9
- package/packages/server/services/optimization.service.js +25 -22
- package/packages/server/services/template.service.js +3 -8
- package/packages/server/toolm/author-sync.service.js +97 -0
- package/packages/server/toolm/index.js +1 -2
- package/packages/server/toolm/package-installer.service.js +47 -50
- package/packages/server/toolm/tool-context.service.js +64 -62
- package/packages/server/toolm/tool-dependency.service.js +28 -30
- package/packages/server/toolm/tool-description-generator-optimized.service.js +55 -55
- package/packages/server/toolm/tool-description-generator.service.js +20 -23
- package/packages/server/toolm/tool-environment.service.js +45 -44
- package/packages/server/toolm/tool-execution.service.js +49 -48
- package/packages/server/toolm/tool-loader.service.js +13 -18
- package/packages/server/toolm/tool-logger.service.js +33 -39
- package/packages/server/toolm/tool-manager.handler.js +17 -15
- package/packages/server/toolm/tool-manual-generator.service.js +107 -87
- package/packages/server/toolm/tool-mode-handlers.service.js +52 -59
- package/packages/server/toolm/tool-storage.service.js +11 -12
- package/packages/server/toolm/tool-sync.service.js +36 -39
- package/packages/server/toolm/tool-utils.js +0 -1
- package/packages/server/toolm/tool-yaml-parser.service.js +12 -11
- package/packages/server/toolm/validate-system.js +56 -84
- package/packages/server/utils/config.js +98 -13
- package/packages/server/utils/logger.js +1 -1
- package/packages/server/utils/port-checker.js +8 -8
- package/packages/server/utils/util.js +470 -467
- package/packages/resources/tools/cognitive-thinking/README.md +0 -284
- package/packages/resources/tools/cognitive-thinking/cognitive-thinking.tool.js +0 -837
- package/packages/server/mcp/sequential-thinking.handler.js +0 -318
- package/packages/server/mcp/think-plan.handler.js +0 -274
- package/packages/server/mcp/thinking-toolkit.handler.js +0 -380
- package/packages/web/0.d1c5a72339dfc32ad86a.js +0 -1
- package/packages/web/112.8807b976372b2b0541a8.js +0 -1
- package/packages/web/130.584c7e365da413f5d9be.js +0 -1
- package/packages/web/142.72c985bc29720f975cca.js +0 -1
- package/packages/web/165.a05fc53bf84d18db36b8.js +0 -2
- package/packages/web/165.a05fc53bf84d18db36b8.js.LICENSE.txt +0 -9
- package/packages/web/203.724ab9f717b80554c397.js +0 -1
- package/packages/web/241.bf941d4f02866795f64a.js +0 -1
- package/packages/web/249.54cfb224af63f5f5ec55.js +0 -1
- package/packages/web/291.6df35042f8f296fca7cd.js +0 -1
- package/packages/web/319.2fab900a31b29873f666.js +0 -1
- package/packages/web/32.c78d866281995ec33a7b.js +0 -1
- package/packages/web/325.9ca297d0f73f38468ce9.js +0 -1
- package/packages/web/366.2f9b48fdbf8eee039e57.js +0 -1
- package/packages/web/378.6be08c612cd5a3ef97dc.js +0 -1
- package/packages/web/393.7a2f817515c5e90623d7.js +0 -1
- package/packages/web/412.062df5f732d5ba203415.js +0 -1
- package/packages/web/426.08656fef4918b3fb19ad.js +0 -1
- package/packages/web/465.2be8018327130a3bd798.js +0 -1
- package/packages/web/48.8ca96fc93667a715e67a.js +0 -1
- package/packages/web/480.44c1f1a2927486ac3d4f.js +0 -1
- package/packages/web/489.e041a8d0db15dc96d607.js +0 -1
- package/packages/web/490.9ffb26c907de020d671b.js +0 -1
- package/packages/web/492.58781369e348d91fc06a.js +0 -1
- package/packages/web/495.ed63e99791a87167c6b3.js +0 -1
- package/packages/web/510.4cc07ab7d30d5c1cd17f.js +0 -1
- package/packages/web/543.3af155ed4fa237664308.js +0 -1
- package/packages/web/567.f04ab60f8e2c2fb0745a.js +0 -1
- package/packages/web/592.f3ad085fa9c1849daa06.js +0 -1
- package/packages/web/616.b03fb801b3433b17750f.js +0 -1
- package/packages/web/617.d88def54921d2c4dc44c.js +0 -1
- package/packages/web/641.d30787d674f548928261.js +0 -1
- package/packages/web/672.5269c8399fa42a5af95d.js +0 -1
- package/packages/web/731.97cab92b71811c502bda.js +0 -1
- package/packages/web/746.3947c6f0235407e420fb.js +0 -1
- package/packages/web/756.a53233b3f3913900d5ac.js +0 -1
- package/packages/web/77.68801af593a28a631fbf.js +0 -1
- package/packages/web/802.53b2bff3cf2a69f7b80c.js +0 -1
- package/packages/web/815.b6dfab82265f56c7e046.js +0 -1
- package/packages/web/821.f5a13e5c735aac244eb9.js +0 -1
- package/packages/web/846.b9bf97d5f559270675ce.js +0 -1
- package/packages/web/869.7c10403f500e6201407f.js +0 -1
- package/packages/web/885.135050364f99e6924fb5.js +0 -1
- package/packages/web/901.fd5aeb9df630609a2b43.js +0 -1
- package/packages/web/928.f67e590de3caa4daa3ae.js +0 -1
- package/packages/web/955.d833403521ba4dd567ee.js +0 -1
- package/packages/web/981.a45cb745cf424044c8c8.js +0 -1
- package/packages/web/992.645320b60c74c8787482.js +0 -1
- package/packages/web/996.ed9a963dc9e7439eca9a.js +0 -1
- package/packages/web/css/codemirror-theme_xq-light.css +0 -43
- package/packages/web/css/codemirror.css +0 -344
- package/packages/web/css/main.196f434e6a88cd448158.css +0 -7278
- package/packages/web/css/terminal-fix.css +0 -571
- package/packages/web/index.html +0 -3
- package/packages/web/main.dceff50c7307dda04873.js +0 -2
- package/packages/web/main.dceff50c7307dda04873.js.LICENSE.txt +0 -3
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sequential Thinking 工具处理器
|
|
3
|
-
*
|
|
4
|
-
* 参考: https://github.com/spences10/mcp-sequentialthinking-tools
|
|
5
|
-
*
|
|
6
|
-
* 功能:
|
|
7
|
-
* - 通过顺序思维实现动态和反思性的问题解决
|
|
8
|
-
* - 支持思维过程的分支和修订
|
|
9
|
-
* - 帮助将复杂问题分解为可管理的步骤
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { logger } from '../utils/logger.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 思考状态管理
|
|
16
|
-
*/
|
|
17
|
-
class ThinkingState {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.thoughts = [];
|
|
20
|
-
this.currentThoughtNumber = 0;
|
|
21
|
-
this.branches = new Map();
|
|
22
|
-
this.revisions = [];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
addThought(thought, metadata = {}) {
|
|
26
|
-
const thoughtObj = {
|
|
27
|
-
number: this.currentThoughtNumber + 1,
|
|
28
|
-
content: thought,
|
|
29
|
-
timestamp: new Date().toISOString(),
|
|
30
|
-
...metadata
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
this.thoughts.push(thoughtObj);
|
|
34
|
-
this.currentThoughtNumber = thoughtObj.number;
|
|
35
|
-
|
|
36
|
-
return thoughtObj;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
reviseThought(thoughtNumber, newThought) {
|
|
40
|
-
const originalThought = this.thoughts.find(t => t.number === thoughtNumber);
|
|
41
|
-
if (!originalThought) {
|
|
42
|
-
throw new Error(`思考 ${thoughtNumber} 不存在`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const revision = {
|
|
46
|
-
originalNumber: thoughtNumber,
|
|
47
|
-
newContent: newThought,
|
|
48
|
-
timestamp: new Date().toISOString()
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
this.revisions.push(revision);
|
|
52
|
-
originalThought.revised = true;
|
|
53
|
-
originalThought.revision = revision;
|
|
54
|
-
|
|
55
|
-
return revision;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
createBranch(fromThoughtNumber, branchId, branchThought) {
|
|
59
|
-
const branch = {
|
|
60
|
-
fromThought: fromThoughtNumber,
|
|
61
|
-
branchId: branchId,
|
|
62
|
-
thoughts: [branchThought],
|
|
63
|
-
timestamp: new Date().toISOString()
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
this.branches.set(branchId, branch);
|
|
67
|
-
return branch;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
getThoughts() {
|
|
71
|
-
return this.thoughts;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getBranches() {
|
|
75
|
-
return Array.from(this.branches.values());
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getRevisions() {
|
|
79
|
-
return this.revisions;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
getSummary() {
|
|
83
|
-
return {
|
|
84
|
-
totalThoughts: this.thoughts.length,
|
|
85
|
-
totalBranches: this.branches.size,
|
|
86
|
-
totalRevisions: this.revisions.length,
|
|
87
|
-
currentThought: this.currentThoughtNumber
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
reset() {
|
|
92
|
-
this.thoughts = [];
|
|
93
|
-
this.currentThoughtNumber = 0;
|
|
94
|
-
this.branches.clear();
|
|
95
|
-
this.revisions = [];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 全局思考状态(可以根据需要改为按会话管理)
|
|
100
|
-
const thinkingState = new ThinkingState();
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 处理 sequential thinking 工具调用
|
|
104
|
-
* @param {object} args - 参数对象
|
|
105
|
-
* @returns {object} MCP 格式的返回结果
|
|
106
|
-
*/
|
|
107
|
-
export async function handleSequentialThinking(args) {
|
|
108
|
-
const {
|
|
109
|
-
thought,
|
|
110
|
-
nextThoughtNeeded = true,
|
|
111
|
-
thoughtNumber,
|
|
112
|
-
totalThoughts = 10,
|
|
113
|
-
isRevision = false,
|
|
114
|
-
revisesThought,
|
|
115
|
-
branchFromThought,
|
|
116
|
-
branchId,
|
|
117
|
-
needsMoreThoughts = false
|
|
118
|
-
} = args;
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
if (!thought) {
|
|
122
|
-
throw new Error('缺少必需参数: thought');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// 处理思考记录
|
|
126
|
-
let thoughtRecord;
|
|
127
|
-
|
|
128
|
-
if (isRevision && revisesThought) {
|
|
129
|
-
// 修订现有思考
|
|
130
|
-
thinkingState.reviseThought(revisesThought, thought);
|
|
131
|
-
thoughtRecord = {
|
|
132
|
-
number: revisesThought,
|
|
133
|
-
type: 'revision',
|
|
134
|
-
revisesThought: revisesThought,
|
|
135
|
-
content: thought
|
|
136
|
-
};
|
|
137
|
-
} else if (branchFromThought && branchId) {
|
|
138
|
-
// 创建分支
|
|
139
|
-
const branch = thinkingState.createBranch(branchFromThought, branchId, thought);
|
|
140
|
-
thoughtRecord = {
|
|
141
|
-
number: branchFromThought,
|
|
142
|
-
type: 'branch',
|
|
143
|
-
branchFromThought: branchFromThought,
|
|
144
|
-
branchId: branchId,
|
|
145
|
-
content: thought
|
|
146
|
-
};
|
|
147
|
-
} else {
|
|
148
|
-
// 添加新思考
|
|
149
|
-
const addedThought = thinkingState.addThought(thought, {
|
|
150
|
-
thoughtNumber: thoughtNumber,
|
|
151
|
-
totalThoughts: totalThoughts,
|
|
152
|
-
nextThoughtNeeded: nextThoughtNeeded,
|
|
153
|
-
needsMoreThoughts: needsMoreThoughts
|
|
154
|
-
});
|
|
155
|
-
thoughtRecord = {
|
|
156
|
-
number: addedThought.number,
|
|
157
|
-
type: 'regular',
|
|
158
|
-
content: thought
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// 获取当前状态摘要
|
|
163
|
-
const summary = thinkingState.getSummary();
|
|
164
|
-
const allThoughts = thinkingState.getThoughts();
|
|
165
|
-
const branches = thinkingState.getBranches();
|
|
166
|
-
const revisions = thinkingState.getRevisions();
|
|
167
|
-
|
|
168
|
-
// 构建响应
|
|
169
|
-
const response = {
|
|
170
|
-
success: true,
|
|
171
|
-
thought: thoughtRecord,
|
|
172
|
-
summary: summary,
|
|
173
|
-
progress: {
|
|
174
|
-
current: thoughtNumber || summary.currentThought,
|
|
175
|
-
total: totalThoughts,
|
|
176
|
-
percentage: Math.round(((thoughtNumber || summary.currentThought) / totalThoughts) * 100)
|
|
177
|
-
},
|
|
178
|
-
nextThoughtNeeded: nextThoughtNeeded || needsMoreThoughts,
|
|
179
|
-
thoughts: allThoughts.map(t => ({
|
|
180
|
-
number: t.number,
|
|
181
|
-
content: t.content,
|
|
182
|
-
revised: t.revised || false
|
|
183
|
-
})),
|
|
184
|
-
...(branches.length > 0 && { branches: branches }),
|
|
185
|
-
...(revisions.length > 0 && { revisions: revisions })
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// 如果不需要更多思考,可以生成最终总结
|
|
189
|
-
if (!nextThoughtNeeded && !needsMoreThoughts) {
|
|
190
|
-
response.finalSummary = generateFinalSummary(allThoughts, branches, revisions);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
logger.debug('Sequential thinking result:', response);
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
content: [
|
|
197
|
-
{
|
|
198
|
-
type: "text",
|
|
199
|
-
text: formatThinkingOutput(response)
|
|
200
|
-
}
|
|
201
|
-
]
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
} catch (error) {
|
|
205
|
-
logger.error('Sequential thinking error:', error);
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* 生成最终总结
|
|
212
|
-
*/
|
|
213
|
-
function generateFinalSummary(thoughts, branches, revisions) {
|
|
214
|
-
const summary = {
|
|
215
|
-
totalSteps: thoughts.length,
|
|
216
|
-
keyInsights: [],
|
|
217
|
-
conclusions: [],
|
|
218
|
-
recommendations: []
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
// 提取关键洞察(可以根据需要改进逻辑)
|
|
222
|
-
thoughts.forEach(thought => {
|
|
223
|
-
if (thought.content.includes('关键') || thought.content.includes('重要') || thought.content.includes('结论')) {
|
|
224
|
-
summary.keyInsights.push({
|
|
225
|
-
step: thought.number,
|
|
226
|
-
content: thought.content
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// 提取结论
|
|
232
|
-
const lastThoughts = thoughts.slice(-3);
|
|
233
|
-
summary.conclusions = lastThoughts.map(t => ({
|
|
234
|
-
step: t.number,
|
|
235
|
-
content: t.content
|
|
236
|
-
}));
|
|
237
|
-
|
|
238
|
-
return summary;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* 格式化思考输出
|
|
243
|
-
*/
|
|
244
|
-
function formatThinkingOutput(response) {
|
|
245
|
-
let output = '';
|
|
246
|
-
|
|
247
|
-
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
248
|
-
output += '🧠 **顺序思考工具**\n';
|
|
249
|
-
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n';
|
|
250
|
-
|
|
251
|
-
// 当前思考
|
|
252
|
-
output += `**思考 ${response.thought.number || response.summary.currentThought}**\n`;
|
|
253
|
-
output += `${response.thought.content}\n\n`;
|
|
254
|
-
|
|
255
|
-
// 进度信息
|
|
256
|
-
output += `**进度**: ${response.progress.current}/${response.progress.total} (${response.progress.percentage}%)\n\n`;
|
|
257
|
-
|
|
258
|
-
// 思考历史
|
|
259
|
-
if (response.thoughts && response.thoughts.length > 0) {
|
|
260
|
-
output += '**思考历史**:\n';
|
|
261
|
-
response.thoughts.forEach(t => {
|
|
262
|
-
const marker = t.revised ? '↩️' : '•';
|
|
263
|
-
output += `${marker} [${t.number}] ${t.content.substring(0, 100)}${t.content.length > 100 ? '...' : ''}\n`;
|
|
264
|
-
});
|
|
265
|
-
output += '\n';
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// 分支信息
|
|
269
|
-
if (response.branches && response.branches.length > 0) {
|
|
270
|
-
output += '**分支**:\n';
|
|
271
|
-
response.branches.forEach(branch => {
|
|
272
|
-
output += ` └─ 分支 ${branch.branchId} (来自思考 ${branch.fromThought})\n`;
|
|
273
|
-
});
|
|
274
|
-
output += '\n';
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// 修订信息
|
|
278
|
-
if (response.revisions && response.revisions.length > 0) {
|
|
279
|
-
output += '**修订**:\n';
|
|
280
|
-
response.revisions.forEach(rev => {
|
|
281
|
-
output += ` ↻ 思考 ${rev.originalNumber} 已修订\n`;
|
|
282
|
-
});
|
|
283
|
-
output += '\n';
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// 下一步
|
|
287
|
-
if (response.nextThoughtNeeded) {
|
|
288
|
-
output += '**下一步**: 继续思考...\n';
|
|
289
|
-
} else {
|
|
290
|
-
output += '**状态**: 思考完成\n';
|
|
291
|
-
if (response.finalSummary) {
|
|
292
|
-
output += '\n**最终总结**:\n';
|
|
293
|
-
output += `- 总步骤数: ${response.finalSummary.totalSteps}\n`;
|
|
294
|
-
if (response.finalSummary.keyInsights.length > 0) {
|
|
295
|
-
output += '- 关键洞察:\n';
|
|
296
|
-
response.finalSummary.keyInsights.forEach(insight => {
|
|
297
|
-
output += ` • [步骤 ${insight.step}] ${insight.content}\n`;
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
output += '\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
304
|
-
|
|
305
|
-
return output;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* 重置思考状态(可选功能)
|
|
310
|
-
*/
|
|
311
|
-
export function resetThinkingState() {
|
|
312
|
-
thinkingState.reset();
|
|
313
|
-
return {
|
|
314
|
-
success: true,
|
|
315
|
-
message: '思考状态已重置'
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Think Plan 工具处理器
|
|
3
|
-
*
|
|
4
|
-
* 功能:
|
|
5
|
-
* - 系统化思考与规划工具
|
|
6
|
-
* - 支持分阶段梳理思考、规划和行动步骤
|
|
7
|
-
* - 强调思考(thought)、计划(plan)与实际行动(action)的结合
|
|
8
|
-
* - 通过编号(thoughtNumber)追踪过程
|
|
9
|
-
* - 不会获取新信息或更改数据库,只会将想法附加到记忆中
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { logger } from '../utils/logger.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 思考和规划条目
|
|
16
|
-
*/
|
|
17
|
-
class ThinkPlanEntry {
|
|
18
|
-
constructor(thoughtNumber, thought, plan, action) {
|
|
19
|
-
this.thoughtNumber = thoughtNumber;
|
|
20
|
-
this.thought = thought;
|
|
21
|
-
this.plan = plan;
|
|
22
|
-
this.action = action;
|
|
23
|
-
this.timestamp = new Date();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
toJSON() {
|
|
27
|
-
return {
|
|
28
|
-
thoughtNumber: this.thoughtNumber,
|
|
29
|
-
thought: this.thought,
|
|
30
|
-
plan: this.plan,
|
|
31
|
-
action: this.action,
|
|
32
|
-
timestamp: this.timestamp.toISOString()
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 思考和规划内存管理
|
|
39
|
-
*/
|
|
40
|
-
class ThinkPlanMemory {
|
|
41
|
-
constructor() {
|
|
42
|
-
this.entries = [];
|
|
43
|
-
this.mutex = new Map(); // 用于会话级别的并发控制
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 添加新的思考和规划条目
|
|
48
|
-
*/
|
|
49
|
-
addEntry(thoughtNumber, thought, plan, action, sessionId = 'default') {
|
|
50
|
-
const entry = new ThinkPlanEntry(thoughtNumber, thought, plan, action);
|
|
51
|
-
|
|
52
|
-
if (!this.mutex.has(sessionId)) {
|
|
53
|
-
this.mutex.set(sessionId, []);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.mutex.get(sessionId).push(entry);
|
|
57
|
-
this.entries.push(entry);
|
|
58
|
-
|
|
59
|
-
logger.debug(`ThinkPlan Entry [${thoughtNumber}] added:`, {
|
|
60
|
-
thought: thought.substring(0, 50) + '...',
|
|
61
|
-
plan: plan.substring(0, 50) + '...',
|
|
62
|
-
action: action.substring(0, 50) + '...'
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return entry;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 获取所有记录
|
|
70
|
-
*/
|
|
71
|
-
getAllEntries(sessionId = 'default') {
|
|
72
|
-
if (sessionId === 'default') {
|
|
73
|
-
return [...this.entries];
|
|
74
|
-
}
|
|
75
|
-
return [...(this.mutex.get(sessionId) || [])];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 根据编号获取特定记录
|
|
80
|
-
*/
|
|
81
|
-
getEntryByNumber(thoughtNumber, sessionId = 'default') {
|
|
82
|
-
const entries = sessionId === 'default' ? this.entries : (this.mutex.get(sessionId) || []);
|
|
83
|
-
return entries.find(entry => entry.thoughtNumber === thoughtNumber) || null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 以 JSON 格式获取所有记录
|
|
88
|
-
*/
|
|
89
|
-
getEntriesAsJSON(sessionId = 'default') {
|
|
90
|
-
const entries = this.getAllEntries(sessionId);
|
|
91
|
-
return JSON.stringify(entries.map(e => e.toJSON()), null, 2);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 清空所有记录
|
|
96
|
-
*/
|
|
97
|
-
clearEntries(sessionId = 'default') {
|
|
98
|
-
if (sessionId === 'default') {
|
|
99
|
-
this.entries = [];
|
|
100
|
-
this.mutex.clear();
|
|
101
|
-
} else {
|
|
102
|
-
this.mutex.delete(sessionId);
|
|
103
|
-
// 从全局 entries 中移除该会话的记录
|
|
104
|
-
this.entries = this.entries.filter(e => {
|
|
105
|
-
// 这里简化处理,实际可能需要更复杂的会话追踪
|
|
106
|
-
return true; // 保留所有记录,只清除会话特定记录
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
logger.info(`ThinkPlan memory cleared for session: ${sessionId}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 获取思考和规划过程的摘要
|
|
114
|
-
*/
|
|
115
|
-
getSummary(sessionId = 'default') {
|
|
116
|
-
const entries = this.getAllEntries(sessionId);
|
|
117
|
-
|
|
118
|
-
if (entries.length === 0) {
|
|
119
|
-
return '暂无思考和规划记录';
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
let summary = `思考和规划过程摘要 (共 ${entries.length} 个步骤):\n\n`;
|
|
123
|
-
|
|
124
|
-
entries.forEach((entry, index) => {
|
|
125
|
-
summary += `${index + 1}. [${entry.thoughtNumber}] ${entry.thought}\n`;
|
|
126
|
-
if (index < entries.length - 1) {
|
|
127
|
-
summary += '\n';
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return summary;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 获取当前记录数量
|
|
136
|
-
*/
|
|
137
|
-
getCount(sessionId = 'default') {
|
|
138
|
-
const entries = this.getAllEntries(sessionId);
|
|
139
|
-
return entries.length;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 全局内存实例
|
|
144
|
-
const thinkPlanMemory = new ThinkPlanMemory();
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 处理 think_and_plan 工具调用
|
|
148
|
-
* @param {object} args - 参数对象
|
|
149
|
-
* @returns {object} MCP 格式的返回结果
|
|
150
|
-
*/
|
|
151
|
-
export async function handleThinkPlan(args) {
|
|
152
|
-
const {
|
|
153
|
-
thought,
|
|
154
|
-
plan,
|
|
155
|
-
action,
|
|
156
|
-
thoughtNumber,
|
|
157
|
-
sessionId = 'default'
|
|
158
|
-
} = args;
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
// 验证必需参数
|
|
162
|
-
if (!thought || thought.trim().length === 0) {
|
|
163
|
-
throw new Error('缺少必需参数: thought');
|
|
164
|
-
}
|
|
165
|
-
if (!plan || plan.trim().length === 0) {
|
|
166
|
-
throw new Error('缺少必需参数: plan');
|
|
167
|
-
}
|
|
168
|
-
if (!action || action.trim().length === 0) {
|
|
169
|
-
throw new Error('缺少必需参数: action');
|
|
170
|
-
}
|
|
171
|
-
if (!thoughtNumber || thoughtNumber.trim().length === 0) {
|
|
172
|
-
throw new Error('缺少必需参数: thoughtNumber');
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// 添加新条目
|
|
176
|
-
const entry = thinkPlanMemory.addEntry(thoughtNumber, thought, plan, action, sessionId);
|
|
177
|
-
const currentCount = thinkPlanMemory.getCount(sessionId);
|
|
178
|
-
|
|
179
|
-
// 构建响应内容
|
|
180
|
-
const response = formatThinkPlanOutput(entry, currentCount);
|
|
181
|
-
|
|
182
|
-
logger.info(`ThinkPlan Entry [${thoughtNumber}] recorded`);
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
content: [
|
|
186
|
-
{
|
|
187
|
-
type: "text",
|
|
188
|
-
text: response
|
|
189
|
-
}
|
|
190
|
-
]
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
} catch (error) {
|
|
194
|
-
logger.error('ThinkPlan error:', error);
|
|
195
|
-
throw error;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 格式化思考和规划输出
|
|
201
|
-
*/
|
|
202
|
-
function formatThinkPlanOutput(entry, currentCount) {
|
|
203
|
-
const timestamp = entry.timestamp.toLocaleString('zh-CN', {
|
|
204
|
-
year: 'numeric',
|
|
205
|
-
month: '2-digit',
|
|
206
|
-
day: '2-digit',
|
|
207
|
-
hour: '2-digit',
|
|
208
|
-
minute: '2-digit',
|
|
209
|
-
second: '2-digit'
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
let output = '';
|
|
213
|
-
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
214
|
-
output += '🧠 **思考和规划记录**\n';
|
|
215
|
-
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n';
|
|
216
|
-
|
|
217
|
-
output += `**思考编号**: [${entry.thoughtNumber}]\n\n`;
|
|
218
|
-
|
|
219
|
-
output += '🤔 **思考内容**:\n';
|
|
220
|
-
output += `${entry.thought}\n\n`;
|
|
221
|
-
|
|
222
|
-
output += '📋 **规划方案**:\n';
|
|
223
|
-
output += `${entry.plan}\n\n`;
|
|
224
|
-
|
|
225
|
-
output += '🎯 **下一步行动**:\n';
|
|
226
|
-
output += `${entry.action}\n\n`;
|
|
227
|
-
|
|
228
|
-
output += `⏰ **记录时间**: ${timestamp}\n\n`;
|
|
229
|
-
output += `📊 **当前已记录**: ${currentCount} 个思考步骤\n`;
|
|
230
|
-
|
|
231
|
-
output += '\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
232
|
-
|
|
233
|
-
return output;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* 获取所有思考和规划记录
|
|
238
|
-
*/
|
|
239
|
-
export function getThinkPlanMemory(sessionId = 'default') {
|
|
240
|
-
return thinkPlanMemory.getAllEntries(sessionId);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* 根据编号获取特定的思考和规划记录
|
|
245
|
-
*/
|
|
246
|
-
export function getThinkPlanMemoryByNumber(thoughtNumber, sessionId = 'default') {
|
|
247
|
-
return thinkPlanMemory.getEntryByNumber(thoughtNumber, sessionId);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* 以 JSON 格式获取所有记录
|
|
252
|
-
*/
|
|
253
|
-
export function getThinkPlanMemoryAsJSON(sessionId = 'default') {
|
|
254
|
-
return thinkPlanMemory.getEntriesAsJSON(sessionId);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* 清空所有记录
|
|
259
|
-
*/
|
|
260
|
-
export function clearThinkPlanMemory(sessionId = 'default') {
|
|
261
|
-
thinkPlanMemory.clearEntries(sessionId);
|
|
262
|
-
return {
|
|
263
|
-
success: true,
|
|
264
|
-
message: `思考和规划记录已清空 (会话: ${sessionId})`
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* 获取思考和规划过程的摘要
|
|
270
|
-
*/
|
|
271
|
-
export function getThinkPlanSummary(sessionId = 'default') {
|
|
272
|
-
return thinkPlanMemory.getSummary(sessionId);
|
|
273
|
-
}
|
|
274
|
-
|