foliko 1.1.64 → 1.1.65
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/.agent/data/plugins-state.json +8 -0
- package/.agent/sessions/cli_default.json +313 -133
- package/package.json +1 -1
- package/plugins/audit-plugin.js +11 -7
- package/plugins/coordinator-plugin.js +14 -12
- package/plugins/data-splitter-plugin.js +323 -0
- package/plugins/default-plugins.js +12 -1
- package/plugins/extension-executor-plugin.js +2 -2
- package/plugins/file-system-plugin.js +68 -50
- package/plugins/gate-trading.js +10 -10
- package/plugins/install-plugin.js +3 -3
- package/plugins/memory-plugin.js +8 -11
- package/plugins/plugin-manager-plugin.js +9 -11
- package/plugins/qq-plugin.js +8 -8
- package/plugins/rules-plugin.js +7 -7
- package/plugins/scheduler-plugin.js +22 -18
- package/plugins/session-plugin.js +14 -14
- package/plugins/storage-plugin.js +11 -10
- package/plugins/subagent-plugin.js +13 -9
- package/plugins/think-plugin.js +63 -59
- package/plugins/tools-plugin.js +8 -8
- package/plugins/weixin-plugin.js +5 -5
- package/src/capabilities/skill-manager.js +23 -15
- package/src/capabilities/workflow-engine.js +2 -2
- package/src/core/agent-chat.js +20 -9
- package/src/executors/mcp-executor.js +11 -9
- package/src/utils/data-splitter.js +345 -0
package/plugins/think-plugin.js
CHANGED
|
@@ -13,8 +13,8 @@ class ThinkPlugin extends Plugin {
|
|
|
13
13
|
super()
|
|
14
14
|
this.name = 'think'
|
|
15
15
|
this.version = '1.0.0'
|
|
16
|
-
this.description = '
|
|
17
|
-
this.priority = 5 //
|
|
16
|
+
this.description = '主动思考插件,支持 LLM 自我唤醒和持续思考'
|
|
17
|
+
this.priority = 5 // 高优先级,早期加载
|
|
18
18
|
|
|
19
19
|
this.config = {
|
|
20
20
|
autoReflect: config.autoReflect === true, // 默认关闭自动反思
|
|
@@ -32,7 +32,7 @@ class ThinkPlugin extends Plugin {
|
|
|
32
32
|
this._continuousTopic = null
|
|
33
33
|
this._continuousMessages = [] // 持续思考的上下文消息
|
|
34
34
|
this._continuousRounds = 0 // 持续思考轮次计数
|
|
35
|
-
this._lastThinkResultHash = null // 上次思考结果 hash
|
|
35
|
+
this._lastThinkResultHash = null // 上次思考结果 hash(用于检测重复)
|
|
36
36
|
this._consecutiveSimilarRounds = 0 // 连续相似轮次计数
|
|
37
37
|
this._maxContinuousRounds = 10 // 默认最大轮次
|
|
38
38
|
this._pendingReflection = null
|
|
@@ -45,14 +45,14 @@ class ThinkPlugin extends Plugin {
|
|
|
45
45
|
|
|
46
46
|
start(framework) {
|
|
47
47
|
// 注册思考工具 - 这些工具可以让主 agent 的 LLM 调用
|
|
48
|
-
// think
|
|
48
|
+
// think 支持工具执行循环,LLM 可以让它完成需要调用工具的任务
|
|
49
49
|
|
|
50
50
|
framework.registerTool({
|
|
51
51
|
name: 'think_now',
|
|
52
|
-
description: '
|
|
52
|
+
description: '触发深度思考,支持调用工具分析项目代码。当需要分析、优化、修改代码或文件时使用此工具。',
|
|
53
53
|
inputSchema: z.object({
|
|
54
|
-
topic: z.string().optional().describe('
|
|
55
|
-
mode: z.enum(['reflect', 'brainstorm', 'analyze', 'plan']).optional().describe('
|
|
54
|
+
topic: z.string().optional().describe('思考主题,不提供则让 LLM 自己决定思考什么'),
|
|
55
|
+
mode: z.enum(['reflect', 'brainstorm', 'analyze', 'plan']).optional().describe('思考模式:reflect=反思、brainstorm=头脑风暴、analyze=分析、plan=计划'),
|
|
56
56
|
depth: z.number().optional().describe('思考深度 1-5')
|
|
57
57
|
}),
|
|
58
58
|
execute: async (args) => {
|
|
@@ -62,11 +62,11 @@ class ThinkPlugin extends Plugin {
|
|
|
62
62
|
|
|
63
63
|
framework.registerTool({
|
|
64
64
|
name: 'think_continue',
|
|
65
|
-
description: '
|
|
65
|
+
description: '持续后台思考,定期输出结果。适用于需要持续分析和迭代的任务。',
|
|
66
66
|
inputSchema: z.object({
|
|
67
|
-
interval: z.number().optional().describe('
|
|
67
|
+
interval: z.number().optional().describe('思考间隔毫秒,默认 30000 (30秒)'),
|
|
68
68
|
topic: z.string().optional().describe('思考主题'),
|
|
69
|
-
maxRounds: z.number().optional().describe('
|
|
69
|
+
maxRounds: z.number().optional().describe('最大轮次,默认 10')
|
|
70
70
|
}),
|
|
71
71
|
execute: async (args) => {
|
|
72
72
|
return await this._startContinuousThinking(args)
|
|
@@ -86,7 +86,7 @@ class ThinkPlugin extends Plugin {
|
|
|
86
86
|
name: 'think_get_thoughts',
|
|
87
87
|
description: '获取思考历史记录',
|
|
88
88
|
inputSchema: z.object({
|
|
89
|
-
limit: z.number().optional().describe('
|
|
89
|
+
limit: z.number().optional().describe('返回条数,默认 10')
|
|
90
90
|
}),
|
|
91
91
|
execute: async (args) => {
|
|
92
92
|
const limit = args.limit || 10
|
|
@@ -113,13 +113,13 @@ class ThinkPlugin extends Plugin {
|
|
|
113
113
|
role: '思考助手',
|
|
114
114
|
description: '主动思考、自我反思、持续思考',
|
|
115
115
|
systemPrompt: `你是一个专业的思考助手。
|
|
116
|
-
|
|
116
|
+
职责:
|
|
117
117
|
1. 根据指定的模式和深度进行思考
|
|
118
118
|
2. 提供深入、有洞察力的分析
|
|
119
|
-
3.
|
|
119
|
+
3. 直接输出思考结果,不说废话
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
-
|
|
121
|
+
重要规则:
|
|
122
|
+
- 只输出思考结果,不需要解释你在做什么
|
|
123
123
|
- 思考要深入、全面
|
|
124
124
|
- 直接给出结论和见解`,
|
|
125
125
|
disableTools: false,
|
|
@@ -133,12 +133,12 @@ class ThinkPlugin extends Plugin {
|
|
|
133
133
|
* @param {string} args.mode - 思考模式
|
|
134
134
|
* @param {number} args.depth - 思考深度
|
|
135
135
|
* @param {Object} args.agent - 外部 agent
|
|
136
|
-
* @param {Array} args.messages -
|
|
136
|
+
* @param {Array} args.messages - 可选,上下文消息数组用于持续对话
|
|
137
137
|
*/
|
|
138
138
|
async _triggerThinking(args) {
|
|
139
139
|
const mode = args.mode || 'reflect'
|
|
140
140
|
const depth = Math.min(args.depth || 2, 5)
|
|
141
|
-
const topic = args.topic || '
|
|
141
|
+
const topic = args.topic || '刚才的对话还有什么可以改进或补充的地方?'
|
|
142
142
|
// 支持外部传入 agent
|
|
143
143
|
const externalAgent = args.agent
|
|
144
144
|
// 支持传入上下文消息
|
|
@@ -157,18 +157,18 @@ class ThinkPlugin extends Plugin {
|
|
|
157
157
|
|
|
158
158
|
const reflectPrompt = this._buildReflectPrompt(mode, depth, topic)
|
|
159
159
|
|
|
160
|
-
// 优先使用外部传入的 agent
|
|
160
|
+
// 优先使用外部传入的 agent,否则使用缓存的 think agent
|
|
161
161
|
const thinkAgent = externalAgent || this._thinkAgent || (this._thinkAgent = this._createThinkSubagent())
|
|
162
162
|
log.info(`[Think] thinkAgent apiKey: ${thinkAgent.apiKey ? thinkAgent.apiKey.substring(0,8) + '...' : 'null'}, provider: ${thinkAgent.provider}, model: ${thinkAgent.model}`)
|
|
163
163
|
|
|
164
164
|
let result
|
|
165
165
|
if (contextMessages && contextMessages.length > 0) {
|
|
166
|
-
//
|
|
166
|
+
// 持续对话模式:传入上下文消息
|
|
167
167
|
const messages = [...contextMessages, { role: 'user', content: reflectPrompt }]
|
|
168
168
|
log.info(`[Think] round with context: contextLen=${contextMessages.length}, totalMsgs=${messages.length}`);
|
|
169
169
|
result = await thinkAgent.chat(messages)
|
|
170
170
|
} else {
|
|
171
|
-
//
|
|
171
|
+
// 普通模式:新对话
|
|
172
172
|
result = await thinkAgent.chat(reflectPrompt)
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -188,12 +188,12 @@ class ThinkPlugin extends Plugin {
|
|
|
188
188
|
this._thoughts = this._thoughts.slice(-100)
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
//
|
|
191
|
+
// 返回消息数组(用于持续对话)
|
|
192
192
|
if (contextMessages) {
|
|
193
193
|
thought.messages = [...contextMessages, { role: 'user', content: reflectPrompt }, { role: 'assistant', content: result.message }]
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
//
|
|
196
|
+
// 触发思考完成事件(使用文档规定的字段结构)
|
|
197
197
|
if (this._framework) {
|
|
198
198
|
this._framework.emit('think:thought_completed', {
|
|
199
199
|
topic: thought.topic,
|
|
@@ -208,9 +208,13 @@ class ThinkPlugin extends Plugin {
|
|
|
208
208
|
|
|
209
209
|
return {
|
|
210
210
|
success: true,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
data: {
|
|
212
|
+
thought,
|
|
213
|
+
message: `【主动思考完成】\n模式: ${mode}\n主题: ${topic}\n\n${result.message || result.error || ''}`
|
|
214
|
+
},
|
|
215
|
+
metadata: {
|
|
216
|
+
messages: result.messages
|
|
217
|
+
}
|
|
214
218
|
}
|
|
215
219
|
} catch (err) {
|
|
216
220
|
this._emitNotification('error', '🧠 思考失败', err.message.slice(0, 100))
|
|
@@ -245,63 +249,63 @@ class ThinkPlugin extends Plugin {
|
|
|
245
249
|
}
|
|
246
250
|
|
|
247
251
|
const modePrompts = {
|
|
248
|
-
reflect: `请${depthDesc[depth]}
|
|
252
|
+
reflect: `请${depthDesc[depth]}:
|
|
249
253
|
|
|
250
|
-
1.
|
|
251
|
-
2.
|
|
252
|
-
3.
|
|
254
|
+
1. 基于之前的思考,检查是否有真正新的论点、分析角度或补充
|
|
255
|
+
2. 如果发现遗漏或更好的思路,请输出
|
|
256
|
+
3. 如果认为之前的思考已经完整、没有新内容可补充,请输出【无新增论点,思考已充分】并结束
|
|
253
257
|
|
|
254
258
|
${topic ? `额外关注: ${topic}` : ''}
|
|
255
259
|
|
|
256
|
-
|
|
260
|
+
请直接输出你的反思结果,不需要重复之前的对话内容。如果确认没有新论点,必须明确输出【无新增论点,思考已充分】。`,
|
|
257
261
|
|
|
258
|
-
brainstorm:
|
|
262
|
+
brainstorm: `请进行头脑风暴,针对以下主题产生更多想法:
|
|
259
263
|
|
|
260
264
|
${topic || '刚才讨论的内容'}
|
|
261
265
|
|
|
262
|
-
产生至少 3-5
|
|
266
|
+
产生至少 3-5 个新的观点或方向,不必拘泥于之前讨论的内容。`,
|
|
263
267
|
|
|
264
|
-
analyze:
|
|
268
|
+
analyze: `请对以下主题进行深度分析:
|
|
265
269
|
|
|
266
270
|
${topic || '刚才讨论的内容'}
|
|
267
271
|
|
|
268
|
-
|
|
269
|
-
-
|
|
270
|
-
-
|
|
271
|
-
-
|
|
272
|
+
分析要点:
|
|
273
|
+
- 根本原因是什么?
|
|
274
|
+
- 有哪些支持/反对的证据?
|
|
275
|
+
- 可能的发展方向?`,
|
|
272
276
|
|
|
273
|
-
plan:
|
|
277
|
+
plan: `基于目前的讨论,请制定下一步计划:
|
|
274
278
|
|
|
275
279
|
${topic || '接下来的行动'}
|
|
276
280
|
|
|
277
|
-
|
|
281
|
+
计划要具体、可执行,包含时间线和预期结果。`
|
|
278
282
|
}
|
|
279
283
|
|
|
280
284
|
return modePrompts[mode] || modePrompts.reflect
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
/**
|
|
284
|
-
*
|
|
288
|
+
* 自动反思(响应完成后)
|
|
285
289
|
*/
|
|
286
290
|
async _autoReflect(data) {
|
|
287
291
|
if (!this._framework) return
|
|
288
292
|
|
|
289
293
|
try {
|
|
290
|
-
//
|
|
294
|
+
// 检查是否需要反思(避免短时间重复反思)
|
|
291
295
|
const lastThought = this._thoughts[this._thoughts.length - 1]
|
|
292
296
|
if (lastThought && Date.now() - lastThought.timestamp.getTime() < 10000) {
|
|
293
297
|
return // 10秒内不重复反思
|
|
294
298
|
}
|
|
295
299
|
|
|
296
300
|
// 构建轻量级反思
|
|
297
|
-
const reflectPrompt =
|
|
301
|
+
const reflectPrompt = `作为助手,请快速检视刚才的回答是否:
|
|
298
302
|
1. 完整回答了用户的问题
|
|
299
303
|
2. 表达清晰易懂
|
|
300
304
|
3. 有没有遗漏关键信息
|
|
301
305
|
|
|
302
|
-
|
|
306
|
+
如果发现不足,请直接补充。如果没问题,请简短回复"检查完毕,无需补充"。`
|
|
303
307
|
|
|
304
|
-
// 使用轻量 Subagent
|
|
308
|
+
// 使用轻量 Subagent 静默思考,不打断用户
|
|
305
309
|
const thinkAgent = this._createThinkSubagent()
|
|
306
310
|
const result = await thinkAgent.chat(reflectPrompt)
|
|
307
311
|
|
|
@@ -316,7 +320,7 @@ ${topic || '接下来的行动'}
|
|
|
316
320
|
|
|
317
321
|
this._thoughts.push(thought)
|
|
318
322
|
|
|
319
|
-
//
|
|
323
|
+
// 如果反思有重要补充,触发事件通知
|
|
320
324
|
if (result.message?.includes('补充') && !result.message?.includes('无需补充')) {
|
|
321
325
|
this._framework.emit('think:reflection_needs_attention', {
|
|
322
326
|
thought,
|
|
@@ -338,17 +342,17 @@ ${topic || '接下来的行动'}
|
|
|
338
342
|
}
|
|
339
343
|
|
|
340
344
|
const interval = args.interval || 30000
|
|
341
|
-
const topic = args.topic || '
|
|
345
|
+
const topic = args.topic || '基于最近的对话,还有什么值得深入思考的方向?'
|
|
342
346
|
const maxRounds = args.maxRounds || 10 // 默认最多10轮
|
|
343
347
|
|
|
344
348
|
this._continuousMode = true
|
|
345
349
|
this._continuousTopic = topic
|
|
346
350
|
this._continuousMessages = [] // 初始化上下文消息
|
|
347
351
|
this._continuousRounds = 0 // 当前轮次计数
|
|
348
|
-
this._lastThinkResultHash = null // 上次思考结果的 hash
|
|
352
|
+
this._lastThinkResultHash = null // 上次思考结果的 hash,用于检测重复
|
|
349
353
|
this._consecutiveSimilarRounds = 0 // 连续相似轮次计数
|
|
350
354
|
this._maxContinuousRounds = maxRounds
|
|
351
|
-
//
|
|
355
|
+
// 注意:不再需要捕获 sessionId,因为总结不加到会话
|
|
352
356
|
|
|
353
357
|
const runThink = async () => {
|
|
354
358
|
if (!this._continuousMode) return
|
|
@@ -363,19 +367,19 @@ ${topic || '接下来的行动'}
|
|
|
363
367
|
|
|
364
368
|
this._continuousRounds++
|
|
365
369
|
|
|
366
|
-
//
|
|
370
|
+
// 更新上下文消息(用于下次思考)
|
|
367
371
|
if (result.messages) {
|
|
368
372
|
this._continuousMessages = result.messages
|
|
369
|
-
//
|
|
373
|
+
// 限制上下文长度,最多保留 10 条消息
|
|
370
374
|
if (this._continuousMessages.length > 10) {
|
|
371
375
|
this._continuousMessages = this._continuousMessages.slice(-10)
|
|
372
376
|
}
|
|
373
377
|
}
|
|
374
378
|
|
|
375
|
-
//
|
|
379
|
+
// 自然停止检测:结果相似度判断 + LLM 主动确认无新论点(第一轮不触发判断)
|
|
376
380
|
const currentResult = (result.thought?.result || '').trim()
|
|
377
|
-
//
|
|
378
|
-
const noNewPoints = this._continuousRounds > 1 && currentResult.includes('
|
|
381
|
+
// 第一轮不判断无新论点(还没有内容可供对比),后续轮次才判断
|
|
382
|
+
const noNewPoints = this._continuousRounds > 1 && currentResult.includes('【无新增论点,思考已充分】')
|
|
379
383
|
const currentHash = this._hashString(currentResult)
|
|
380
384
|
if (this._lastThinkResultHash !== null && currentHash === this._lastThinkResultHash) {
|
|
381
385
|
this._consecutiveSimilarRounds++
|
|
@@ -384,7 +388,7 @@ ${topic || '接下来的行动'}
|
|
|
384
388
|
}
|
|
385
389
|
this._lastThinkResultHash = currentHash
|
|
386
390
|
|
|
387
|
-
//
|
|
391
|
+
// 满足自然停止条件:LLM 主动确认无新论点 或 连续3轮相似 或 达到最大轮次
|
|
388
392
|
const shouldStopNaturally =
|
|
389
393
|
noNewPoints ||
|
|
390
394
|
this._consecutiveSimilarRounds >= 3 ||
|
|
@@ -414,8 +418,8 @@ ${topic || '接下来的行动'}
|
|
|
414
418
|
|
|
415
419
|
return {
|
|
416
420
|
success: true,
|
|
417
|
-
|
|
418
|
-
}
|
|
421
|
+
data: `【持续思考已启动】\n间隔: ${interval}ms\n主题: ${topic}\n\nLLM 将定期自动思考并在有新想法时通知你。`
|
|
422
|
+
}
|
|
419
423
|
}
|
|
420
424
|
|
|
421
425
|
/**
|
|
@@ -433,10 +437,10 @@ ${topic || '接下来的行动'}
|
|
|
433
437
|
this._continuousRounds = 0
|
|
434
438
|
this._lastThinkResultHash = null
|
|
435
439
|
this._consecutiveSimilarRounds = 0
|
|
436
|
-
this._emitNotification('info', '
|
|
440
|
+
this._emitNotification('info', 'i️ 持续思考已停止', `共思考 ${rounds} 轮`)
|
|
437
441
|
return {
|
|
438
442
|
success: true,
|
|
439
|
-
|
|
443
|
+
data: '持续思考已停止'
|
|
440
444
|
}
|
|
441
445
|
}
|
|
442
446
|
|
|
@@ -469,7 +473,7 @@ ${topic || '接下来的行动'}
|
|
|
469
473
|
}
|
|
470
474
|
|
|
471
475
|
/**
|
|
472
|
-
* 字符串 hash
|
|
476
|
+
* 字符串 hash(用于判断思考结果是否重复)
|
|
473
477
|
*/
|
|
474
478
|
_hashString(str) {
|
|
475
479
|
if (!str || str.length === 0) return ''
|
package/plugins/tools-plugin.js
CHANGED
|
@@ -77,13 +77,13 @@ class ToolsPlugin extends Plugin {
|
|
|
77
77
|
await framework.reloadPlugin(args.pluginName)
|
|
78
78
|
return {
|
|
79
79
|
success: true,
|
|
80
|
-
|
|
80
|
+
data: `Plugin '${args.pluginName}' reloaded successfully`
|
|
81
81
|
}
|
|
82
82
|
} else {
|
|
83
83
|
await framework.reloadAllPlugins()
|
|
84
84
|
return {
|
|
85
85
|
success: true,
|
|
86
|
-
|
|
86
|
+
data: 'All plugins reloaded successfully'
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
} catch (err) {
|
|
@@ -104,7 +104,7 @@ class ToolsPlugin extends Plugin {
|
|
|
104
104
|
const plugins = framework.pluginManager.getAllKnown()
|
|
105
105
|
return {
|
|
106
106
|
success: true,
|
|
107
|
-
|
|
107
|
+
data: plugins.map(p => ({
|
|
108
108
|
name: p.name,
|
|
109
109
|
status: p.status,
|
|
110
110
|
enabled: p.enabled,
|
|
@@ -125,7 +125,7 @@ class ToolsPlugin extends Plugin {
|
|
|
125
125
|
execute: async (args) => {
|
|
126
126
|
try {
|
|
127
127
|
await framework.enablePlugin(args.name)
|
|
128
|
-
return { success: true,
|
|
128
|
+
return { success: true, data: `插件 '${args.name}' 已启用` }
|
|
129
129
|
} catch (err) {
|
|
130
130
|
return { success: false, error: err.message }
|
|
131
131
|
}
|
|
@@ -142,7 +142,7 @@ class ToolsPlugin extends Plugin {
|
|
|
142
142
|
execute: async (args) => {
|
|
143
143
|
try {
|
|
144
144
|
await framework.disablePlugin(args.name)
|
|
145
|
-
return { success: true,
|
|
145
|
+
return { success: true, data: `插件 '${args.name}' 已禁用` }
|
|
146
146
|
} catch (err) {
|
|
147
147
|
return { success: false, error: err.message }
|
|
148
148
|
}
|
|
@@ -158,7 +158,7 @@ class ToolsPlugin extends Plugin {
|
|
|
158
158
|
const tools = framework.getTools()
|
|
159
159
|
return {
|
|
160
160
|
success: true,
|
|
161
|
-
|
|
161
|
+
data: tools.map(t => ({
|
|
162
162
|
name: t.name,
|
|
163
163
|
description: t.description
|
|
164
164
|
}))
|
|
@@ -180,7 +180,7 @@ class ToolsPlugin extends Plugin {
|
|
|
180
180
|
}
|
|
181
181
|
return {
|
|
182
182
|
success: true,
|
|
183
|
-
|
|
183
|
+
data: plugin.config || {}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
})
|
|
@@ -196,7 +196,7 @@ class ToolsPlugin extends Plugin {
|
|
|
196
196
|
execute: async (args) => {
|
|
197
197
|
try {
|
|
198
198
|
const newConfig = framework.updatePluginConfig(args.name, args.config)
|
|
199
|
-
return { success: true,
|
|
199
|
+
return { success: true, data: `插件 '${args.name}' 配置已更新`, metadata: { config: newConfig } }
|
|
200
200
|
} catch (err) {
|
|
201
201
|
return { success: false, error: err.message }
|
|
202
202
|
}
|
package/plugins/weixin-plugin.js
CHANGED
|
@@ -158,7 +158,7 @@ class WeixinPlugin extends Plugin {
|
|
|
158
158
|
}
|
|
159
159
|
await this._bot.sendImage(this._myUserId, imagePath)
|
|
160
160
|
// log.info(` 图片发送成功: ${path.basename(imagePath)}`)
|
|
161
|
-
return { success: true,
|
|
161
|
+
return { success: true, data: '图片发送成功' }
|
|
162
162
|
} catch (err) {
|
|
163
163
|
log.error(` 图片发送失败: ${err.message}`)
|
|
164
164
|
return { error: err.message }
|
|
@@ -181,7 +181,7 @@ class WeixinPlugin extends Plugin {
|
|
|
181
181
|
}
|
|
182
182
|
await this._bot.sendFile(this._myUserId, filePath, fileName)
|
|
183
183
|
// log.info(` 文件发送成功: ${fileName || path.basename(filePath)}`)
|
|
184
|
-
return { success: true,
|
|
184
|
+
return { success: true, data: '文件发送成功' }
|
|
185
185
|
} catch (err) {
|
|
186
186
|
log.error(` 文件发送失败: ${err.message}`)
|
|
187
187
|
return { error: err.message }
|
|
@@ -205,7 +205,7 @@ class WeixinPlugin extends Plugin {
|
|
|
205
205
|
const opts = playLength ? { playLength } : {}
|
|
206
206
|
await this._bot.sendVideo(this._myUserId, videoPath, opts)
|
|
207
207
|
// log.info(` 视频发送成功: ${path.basename(videoPath)}`)
|
|
208
|
-
return { success: true,
|
|
208
|
+
return { success: true, data: '视频发送成功' }
|
|
209
209
|
} catch (err) {
|
|
210
210
|
log.error(` 视频发送失败: ${err.message}`)
|
|
211
211
|
return { error: err.message }
|
|
@@ -228,7 +228,7 @@ class WeixinPlugin extends Plugin {
|
|
|
228
228
|
}
|
|
229
229
|
await this._bot.sendVoice(this._myUserId, voicePath)
|
|
230
230
|
// log.info(` 语音发送成功: ${path.basename(voicePath)}`)
|
|
231
|
-
return { success: true,
|
|
231
|
+
return { success: true, data: '语音发送成功' }
|
|
232
232
|
} catch (err) {
|
|
233
233
|
log.error(` 语音发送失败: ${err.message}`)
|
|
234
234
|
return { error: err.message }
|
|
@@ -247,7 +247,7 @@ class WeixinPlugin extends Plugin {
|
|
|
247
247
|
}
|
|
248
248
|
try {
|
|
249
249
|
await this._bot.send(this._myUserId, message)
|
|
250
|
-
return { success: true,
|
|
250
|
+
return { success: true, data: '消息发送成功' }
|
|
251
251
|
} catch (err) {
|
|
252
252
|
log.error(` 消息发送失败: ${err.message}`)
|
|
253
253
|
return { error: err.message }
|
|
@@ -175,9 +175,11 @@ class SkillManagerPlugin extends Plugin {
|
|
|
175
175
|
}
|
|
176
176
|
return {
|
|
177
177
|
success: true,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
data: skill.content,
|
|
179
|
+
metadata: {
|
|
180
|
+
name: skill.name,
|
|
181
|
+
description: skill.metadata?.description || '',
|
|
182
|
+
},
|
|
181
183
|
};
|
|
182
184
|
},
|
|
183
185
|
});
|
|
@@ -191,8 +193,10 @@ class SkillManagerPlugin extends Plugin {
|
|
|
191
193
|
this.reload(this._framework);
|
|
192
194
|
return {
|
|
193
195
|
success: true,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
+
data: `Skills reloaded. Total: ${this._skills.size}`,
|
|
197
|
+
metadata: {
|
|
198
|
+
skills: Array.from(this._skills.keys()),
|
|
199
|
+
},
|
|
196
200
|
};
|
|
197
201
|
},
|
|
198
202
|
});
|
|
@@ -212,8 +216,8 @@ class SkillManagerPlugin extends Plugin {
|
|
|
212
216
|
const refs = this.listReferences(args.skill);
|
|
213
217
|
return {
|
|
214
218
|
success: true,
|
|
215
|
-
|
|
216
|
-
|
|
219
|
+
data: refs,
|
|
220
|
+
metadata: { skill: args.skill },
|
|
217
221
|
};
|
|
218
222
|
}
|
|
219
223
|
|
|
@@ -226,9 +230,11 @@ class SkillManagerPlugin extends Plugin {
|
|
|
226
230
|
}
|
|
227
231
|
return {
|
|
228
232
|
success: true,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
data: content,
|
|
234
|
+
metadata: {
|
|
235
|
+
skill: args.skill,
|
|
236
|
+
reference: args.reference,
|
|
237
|
+
},
|
|
232
238
|
};
|
|
233
239
|
},
|
|
234
240
|
});
|
|
@@ -244,8 +250,8 @@ class SkillManagerPlugin extends Plugin {
|
|
|
244
250
|
const scripts = this.listScripts(args.skill);
|
|
245
251
|
return {
|
|
246
252
|
success: true,
|
|
247
|
-
|
|
248
|
-
|
|
253
|
+
data: scripts,
|
|
254
|
+
metadata: { skill: args.skill },
|
|
249
255
|
};
|
|
250
256
|
},
|
|
251
257
|
});
|
|
@@ -268,9 +274,11 @@ class SkillManagerPlugin extends Plugin {
|
|
|
268
274
|
}
|
|
269
275
|
return {
|
|
270
276
|
success: true,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
277
|
+
data: content,
|
|
278
|
+
metadata: {
|
|
279
|
+
skill: args.skill,
|
|
280
|
+
script: args.script,
|
|
281
|
+
},
|
|
274
282
|
};
|
|
275
283
|
},
|
|
276
284
|
});
|
|
@@ -870,8 +870,8 @@ class WorkflowPlugin extends Plugin {
|
|
|
870
870
|
this.reload(this._framework);
|
|
871
871
|
return {
|
|
872
872
|
success: true,
|
|
873
|
-
|
|
874
|
-
workflows: Array.from(this._workflows.keys()),
|
|
873
|
+
data: `Workflows reloaded. Total: ${this._workflows.size}`,
|
|
874
|
+
metadata: { workflows: Array.from(this._workflows.keys()) },
|
|
875
875
|
};
|
|
876
876
|
},
|
|
877
877
|
});
|
package/src/core/agent-chat.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
ToolLoopAgent,
|
|
16
16
|
isLoopFinished,
|
|
17
17
|
} = require('ai');
|
|
18
|
+
const { autoSplitToolResult } = require('../../plugins/data-splitter-plugin');
|
|
18
19
|
const { cleanResponse } = require('../utils');
|
|
19
20
|
const { ChatQueueManager } = require('../utils/chat-queue');
|
|
20
21
|
const { TokenCounter } = require('./token-counter');
|
|
@@ -853,19 +854,29 @@ class AgentChatHandler extends EventEmitter {
|
|
|
853
854
|
logger.info(`[Tool] Call: ${toolName}`);
|
|
854
855
|
try {
|
|
855
856
|
const result = await toolDef.execute(cleanedArgs, this.agent.framework);
|
|
856
|
-
|
|
857
|
-
//
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
857
|
+
|
|
858
|
+
// 自动检测大工具结果,透明分拆
|
|
859
|
+
// 仅在数据分拆插件已加载时生效
|
|
860
|
+
let finalResult = result;
|
|
861
|
+
try {
|
|
862
|
+
const splitCheck = await autoSplitToolResult(toolName, result, this.agent.framework);
|
|
863
|
+
if (splitCheck.wasSplit && splitCheck.result) {
|
|
864
|
+
finalResult = splitCheck.result;
|
|
865
|
+
logger.info(
|
|
866
|
+
`[AutoSplit] 工具 "${toolName}" 结果过大,已自动分拆处理`
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
} catch (splitErr) {
|
|
870
|
+
// 分拆失败不阻断主流程,继续使用原始结果
|
|
871
|
+
logger.warn(`[AutoSplit] 自动分拆跳过: ${splitErr.message}`);
|
|
863
872
|
}
|
|
864
|
-
|
|
873
|
+
|
|
874
|
+
this.emit('tool-result', { name: toolName, args: cleanedArgs, result: finalResult });
|
|
875
|
+
return finalResult;
|
|
865
876
|
} catch (err) {
|
|
866
877
|
this.emit('tool-error', { name: toolName, args: cleanedArgs, error: err.message });
|
|
867
878
|
// 返回错误信息字符串,而不是抛出异常
|
|
868
|
-
return
|
|
879
|
+
return { success: false,error: err.message}
|
|
869
880
|
}
|
|
870
881
|
},
|
|
871
882
|
};
|
|
@@ -307,7 +307,7 @@ class MCPExecutorPlugin extends Plugin {
|
|
|
307
307
|
|
|
308
308
|
return {
|
|
309
309
|
success: true,
|
|
310
|
-
|
|
310
|
+
data: {
|
|
311
311
|
name: toolInfo.name,
|
|
312
312
|
description: toolInfo.description,
|
|
313
313
|
required,
|
|
@@ -405,7 +405,7 @@ class MCPExecutorPlugin extends Plugin {
|
|
|
405
405
|
source: 'mcp',
|
|
406
406
|
});
|
|
407
407
|
|
|
408
|
-
return { success: true,
|
|
408
|
+
return { success: true, data: execResult };
|
|
409
409
|
} catch (err) {
|
|
410
410
|
log.error(` Tool '${tool}' failed:`, err.message);
|
|
411
411
|
|
|
@@ -450,7 +450,7 @@ class MCPExecutorPlugin extends Plugin {
|
|
|
450
450
|
});
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
|
-
return { success: true, servers };
|
|
453
|
+
return { success: true, data: servers };
|
|
454
454
|
},
|
|
455
455
|
});
|
|
456
456
|
|
|
@@ -481,8 +481,10 @@ class MCPExecutorPlugin extends Plugin {
|
|
|
481
481
|
|
|
482
482
|
return {
|
|
483
483
|
success: true,
|
|
484
|
-
|
|
485
|
-
|
|
484
|
+
data: 'MCP 配置已重载',
|
|
485
|
+
metadata: {
|
|
486
|
+
servers: Object.keys(config.mcpServers || {}),
|
|
487
|
+
},
|
|
486
488
|
};
|
|
487
489
|
} catch (err) {
|
|
488
490
|
log.error(' Reload error:', err);
|
|
@@ -507,7 +509,7 @@ class MCPExecutorPlugin extends Plugin {
|
|
|
507
509
|
if (enabled) {
|
|
508
510
|
// 启用服务器
|
|
509
511
|
if (clientInfo && clientInfo.enabled) {
|
|
510
|
-
return { success: true,
|
|
512
|
+
return { success: true, data: `MCP 服务器 '${server}' 已经是开启状态` };
|
|
511
513
|
}
|
|
512
514
|
// 如果服务器从未连接过,也检查配置中的 enabled 状态
|
|
513
515
|
if (!clientInfo && serverConfig && serverConfig.enabled === false) {
|
|
@@ -527,7 +529,7 @@ class MCPExecutorPlugin extends Plugin {
|
|
|
527
529
|
// 保存 enabled 状态到配置文件
|
|
528
530
|
await this._saveMCPServerEnabled(server, true);
|
|
529
531
|
this._refreshAllAgentsMCPPrompt(this._framework);
|
|
530
|
-
return { success: true,
|
|
532
|
+
return { success: true, data: `MCP 服务器 '${server}' 已开启` };
|
|
531
533
|
} else {
|
|
532
534
|
return { success: false, error: '服务器配置不存在,需要重载配置' };
|
|
533
535
|
}
|
|
@@ -555,10 +557,10 @@ class MCPExecutorPlugin extends Plugin {
|
|
|
555
557
|
// 保存 enabled 状态到配置文件
|
|
556
558
|
await this._saveMCPServerEnabled(server, false);
|
|
557
559
|
this._refreshAllAgentsMCPPrompt(this._framework);
|
|
558
|
-
return { success: true,
|
|
560
|
+
return { success: true, data: `MCP 服务器 '${server}' 已关闭` };
|
|
559
561
|
}
|
|
560
562
|
|
|
561
|
-
return { success: true,
|
|
563
|
+
return { success: true, data: `MCP 服务器 '${server}' 状态未变化` };
|
|
562
564
|
},
|
|
563
565
|
});
|
|
564
566
|
|