foliko 1.1.13 → 1.1.15
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 +1 -1
- package/.agent/data/weixin/images/file_1776188148383jpg +0 -0
- package/.agent/data/weixin/images/file_1776188458326.jpg +0 -0
- package/.agent/data/weixin/images/file_1776188689423.jpg +0 -0
- package/.agent/data/weixin/images/file_1776188813604.jpg +0 -0
- package/.agent/data/weixin/images/file_1776189097450.jpg +0 -0
- package/.agent/data/weixin/videos/file_1776188318431.mp4 +0 -0
- package/.agent/mcp_config.json +7 -0
- package/.agent/memory/feedback/mnxe0cxc-14l6q5.md +17 -0
- package/.agent/memory/feedback/mnxe11pa-nxf577.md +9 -0
- package/.agent/memory/feedback/mnxe1an2-84faff.md +9 -0
- package/.agent/memory/feedback/mnxgcfj0-qg3wjc.md +9 -0
- package/.agent/memory/feedback/mnxgcn3y-40mqss.md +9 -0
- package/.agent/memory/feedback/mnxgcxq9-jm7ydl.md +9 -0
- package/.agent/memory/feedback/mnxgdyfj-pzjvkb.md +9 -0
- package/.agent/memory/feedback/mnxge3z1-7vyit1.md +9 -0
- package/.agent/memory/feedback/mnxhrg28-41hhjr.md +9 -0
- package/.agent/memory/feedback/mnxhrx0e-yth94k.md +9 -0
- package/.agent/memory/feedback/mnxhs3jd-rvx8aq.md +9 -0
- package/.agent/memory/feedback/mnxhs7p7-g5rtn9.md +9 -0
- package/.agent/memory/feedback/mnxhslx5-oqwuhr.md +9 -0
- package/.agent/memory/feedback/mnxhsvd6-nuyvvc.md +9 -0
- package/.agent/memory/project/mnxegq6z-5fc64w.md +22 -0
- package/.agent/memory/project/mnxh2w4r-le9hur.md +17 -0
- package/.agent/memory/project/mnxhq2yv-9qa8ay.md +31 -0
- package/.agent/memory/project/mnxhql11-iaun2o.md +34 -0
- package/.agent/memory/project/mnxhr78p-jpg7eq.md +23 -0
- package/.agent/memory/reference/mnxe0oa9-p6wzk6.md +27 -0
- package/.agent/memory/reference/mnxehcll-kcrmpf.md +29 -0
- package/.agent/memory/reference/mnxei0ts-jw091y.md +18 -0
- package/.agent/memory/reference/mnxfnrr4-rski36.md +40 -0
- package/.agent/memory/reference/mnxfo6n5-af9zls.md +18 -0
- package/.agent/memory/reference/mnxh2ady-u6cmvk.md +61 -0
- package/.agent/memory/reference/mnxhqdqh-ucsbsk.md +31 -0
- package/.agent/memory/reference/mnxiixyp-rz2gvw.md +34 -0
- package/.agent/memory/user/mnxhqxk3-vjjhlf.md +23 -0
- package/.agent/sessions/cli_default.json +11 -639
- package/.agent/sessions/weixin_o9cq80zgZqKPA2-s59PN43GdDy1w@im.wechat.json +25 -0
- package/.claude/settings.local.json +23 -1
- package/cli/src/commands/chat.js +9 -15
- package/cli/src/ui/chat-ui.js +40 -71
- package/package.json +4 -2
- package/plugins/default-plugins.js +5 -5
- package/plugins/file-system-plugin.js +1 -1
- package/plugins/memory-plugin.js +12 -12
- package/plugins/plugin-manager-plugin.js +1 -0
- package/plugins/subagent-plugin.js +55 -1
- package/plugins/telegram-plugin.js +9 -6
- package/plugins/weixin-plugin.js +75 -78
- package/src/core/agent-chat.js +468 -1612
- package/src/core/agent.js +53 -134
- package/src/core/chat-session.js +423 -0
- package/src/core/context-compressor.js +473 -0
- package/src/core/context-manager.js +0 -48
- package/src/core/framework.js +95 -68
- package/src/core/index.js +11 -0
- package/src/core/notification-manager.js +125 -0
- package/src/core/subagent.js +295 -0
- package/src/core/token-counter.js +190 -0
- package/src/core/tool-executor.js +270 -0
- package/src/executors/mcp-executor.js +14 -1
- package/src/utils/download.js +596 -0
- package/system.md +312 -2373
- package/.agent/agents/code-assistant.json +0 -17
- package/.agent/agents/email-assistant.json +0 -14
- package/.agent/agents/file-assistant.json +0 -18
- package/.agent/agents/orchestrator-demo.md +0 -53
- package/.agent/agents/orchestrator.json +0 -7
- package/.agent/agents/poster-expert.md +0 -228
- package/.agent/agents/system-assistant.json +0 -15
- package/.agent/agents/web-assistant.json +0 -12
- package/.agent/memory/feedback/mnv3nu27-3o15pf.md +0 -9
- package/.agent/memory/feedback/mnv3o078-b959yj.md +0 -9
- package/.agent/memory/feedback/mnv3o6ej-u0fif5.md +0 -9
- package/.agent/memory/feedback/mnv3obgl-bkkjoj.md +0 -9
- package/.agent/memory/feedback/mnv4a3js-dv6onx.md +0 -9
- package/.agent/memory/feedback/mnv4aacm-sxxowp.md +0 -9
- package/.agent/memory/feedback/mnv4ahto-w40ffm.md +0 -9
- package/.agent/memory/feedback/mnv4anvp-3cs06y.md +0 -9
- package/.agent/memory/feedback/mnvzgvtd-0o2900.md +0 -9
- package/.agent/memory/feedback/mnvzhajn-swbx61.md +0 -15
- package/.agent/memory/feedback/mnvzhgsp-p5vog3.md +0 -9
- package/.agent/memory/feedback/mnvzho0c-fgql7q.md +0 -14
- package/.agent/memory/feedback/mnvzhtzq-ufr5at.md +0 -9
- package/.agent/memory/feedback/mnvzhyb3-9byq2z.md +0 -9
- package/.agent/memory/feedback/mnvzi7hp-hyeafp.md +0 -9
- package/.agent/memory/feedback/mnvzibph-z7rwp5.md +0 -9
- package/.agent/memory/feedback/mnvzilys-7h176w.md +0 -14
- package/.agent/memory/feedback/mnvziuh5-zjshci.md +0 -9
- package/.agent/memory/feedback/mnw07wde-6zqsc8.md +0 -9
- package/.agent/memory/feedback/mnw084bp-j0ba2a.md +0 -9
- package/.agent/memory/user/mnv3n62r-y0h79j.md +0 -21
- package/.agent/memory/user/mnv3n9yf-ead4g8.md +0 -13
- package/.agent/memory/user/mnv3ne3j-82tq1k.md +0 -19
- package/.agent/memory/user/mnv3nhgm-g2s2us.md +0 -11
- package/.agent/memory/user/mnv3nl9u-ejd998.md +0 -16
- package/.agent/memory/user/mnv3nofp-ya5szl.md +0 -10
- package/.agent/memory/user/mnv49qne-bhk0ki.md +0 -9
- package/.agent/memory/user/mnv49w3y-rzr8ju.md +0 -13
- package/.agent/sessions/test.json +0 -16
- package/plugins/python-plugin-loader.js.bak +0 -856
- package/src/core/agent-context.js +0 -188
package/plugins/weixin-plugin.js
CHANGED
|
@@ -11,9 +11,10 @@ const { Plugin } = require('../src/core/plugin-base')
|
|
|
11
11
|
const { logger } = require('../src/utils/logger')
|
|
12
12
|
const log = logger.child('WeChat')
|
|
13
13
|
const {cleanResponse} =require('../src/utils')
|
|
14
|
+
const {FileDownloader} = require('../src/utils/download')
|
|
14
15
|
const removeMarkdown = require('remove-markdown');
|
|
15
16
|
const { z } = require('zod')
|
|
16
|
-
const { WeixinBot
|
|
17
|
+
const { WeixinBot} = require('@chnak/weixin-bot')
|
|
17
18
|
const fs = require('fs')
|
|
18
19
|
const path = require('path')
|
|
19
20
|
|
|
@@ -54,6 +55,13 @@ class WeixinPlugin extends Plugin {
|
|
|
54
55
|
this._qrcodeTerminal = null
|
|
55
56
|
this._origStderrWrite = null
|
|
56
57
|
this._initialized = false
|
|
58
|
+
const saveDir = path.join(process.cwd(), '.agent', 'data', this.name)
|
|
59
|
+
this.downloader=new FileDownloader({
|
|
60
|
+
retries: 3,
|
|
61
|
+
baseDir:saveDir
|
|
62
|
+
})
|
|
63
|
+
this.agent=null
|
|
64
|
+
this.sessionId=null
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
install(framework) {
|
|
@@ -246,7 +254,6 @@ class WeixinPlugin extends Plugin {
|
|
|
246
254
|
// 防止重复初始化
|
|
247
255
|
if (this._initialized) return this
|
|
248
256
|
this._initialized = true
|
|
249
|
-
|
|
250
257
|
// 获取 SessionPlugin 引用
|
|
251
258
|
this._sessionPlugin = framework.pluginManager.get('session')
|
|
252
259
|
|
|
@@ -318,7 +325,9 @@ class WeixinPlugin extends Plugin {
|
|
|
318
325
|
// 记录机器人自己的 userId(用于发送媒体)
|
|
319
326
|
this._myUserId = creds.userId
|
|
320
327
|
// log.info(' 已记录机器人 userId:', this._myUserId)
|
|
321
|
-
|
|
328
|
+
const {agent,sessionId} = this._getSessionAgent(creds.userId)
|
|
329
|
+
const sessionScope = agent.createSessionScope(sessionId);
|
|
330
|
+
|
|
322
331
|
// 注册消息处理
|
|
323
332
|
this._bot.onMessage(async (msg) => {
|
|
324
333
|
await this._handleMessage(msg)
|
|
@@ -360,12 +369,19 @@ class WeixinPlugin extends Plugin {
|
|
|
360
369
|
return agents.length > 0 ? agents[agents.length - 1] : null
|
|
361
370
|
}
|
|
362
371
|
|
|
372
|
+
_on_event_message(){
|
|
373
|
+
const {sessionId}=this.ge
|
|
374
|
+
const sessionScope = this.agent.createSessionScope(sessionId);
|
|
375
|
+
sessionScope.on('stream:chunk', ({ chunk }) => {})
|
|
376
|
+
}
|
|
377
|
+
|
|
363
378
|
/**
|
|
364
379
|
* 获取或创建会话Agent
|
|
365
380
|
* 使用 SessionPlugin 统一管理会话历史
|
|
366
381
|
*/
|
|
367
382
|
_getSessionAgent(userId) {
|
|
368
383
|
const sessionId=`weixin_${userId}`
|
|
384
|
+
this.sessionId=sessionId
|
|
369
385
|
// 检查缓存
|
|
370
386
|
if (this._sessionAgents.has(userId)) {
|
|
371
387
|
const agent = this._sessionAgents.get(userId)
|
|
@@ -390,13 +406,6 @@ class WeixinPlugin extends Plugin {
|
|
|
390
406
|
metadata: { platform: 'weixin', userId }
|
|
391
407
|
})
|
|
392
408
|
}
|
|
393
|
-
const sessionScope = agent.createSessionScope(sessionId);
|
|
394
|
-
// sessionScope.on('stream:chunk', ({chunk}) => {
|
|
395
|
-
// if (chunk.type === 'text') {
|
|
396
|
-
// process.stdout.write(chunk.text);
|
|
397
|
-
// }
|
|
398
|
-
// });
|
|
399
|
-
// log.info(` Session ready for user: ${userId}`)
|
|
400
409
|
return { agent, sessionId }
|
|
401
410
|
}
|
|
402
411
|
|
|
@@ -426,23 +435,26 @@ class WeixinPlugin extends Plugin {
|
|
|
426
435
|
break
|
|
427
436
|
|
|
428
437
|
case 'image':
|
|
429
|
-
// log.info(` 收到图片消息`)
|
|
430
|
-
await this._processMediaChat(userId, '[用户发送了图片]', msg)
|
|
431
|
-
break
|
|
432
|
-
|
|
433
438
|
case 'file':
|
|
434
|
-
// log.info(` 收到文件消息: ${msg.fileName || 'unknown'}`)
|
|
435
|
-
await this._processMediaChat(userId, `[用户发送了文件: ${msg.fileName || 'unknown'}]`, msg)
|
|
436
|
-
break
|
|
437
|
-
|
|
438
439
|
case 'video':
|
|
439
|
-
// log.info(` 收到视频消息`)
|
|
440
|
-
await this._processMediaChat(userId, '[用户发送了视频]', msg)
|
|
441
|
-
break
|
|
442
|
-
|
|
443
440
|
case 'voice':
|
|
444
441
|
// log.info(` 收到语音消息`)
|
|
445
|
-
|
|
442
|
+
const type_dict={
|
|
443
|
+
image:"图片",
|
|
444
|
+
file:"文件",
|
|
445
|
+
video:"视频",
|
|
446
|
+
voice:"音频"
|
|
447
|
+
}
|
|
448
|
+
const files=await this._save_file(msg)
|
|
449
|
+
|
|
450
|
+
await this._processChat(userId, `
|
|
451
|
+
[用户发送了${type_dict[msg.type]}消息]\n
|
|
452
|
+
文件列表:\n
|
|
453
|
+
${JSON.stringify(files,null,2)} \n
|
|
454
|
+
|
|
455
|
+
*重要:* 不要试图读取文件内容!
|
|
456
|
+
`
|
|
457
|
+
, msg)
|
|
446
458
|
break
|
|
447
459
|
|
|
448
460
|
default:
|
|
@@ -452,49 +464,30 @@ class WeixinPlugin extends Plugin {
|
|
|
452
464
|
}
|
|
453
465
|
}
|
|
454
466
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
try {
|
|
470
|
-
await this._bot.sendTyping(userId)
|
|
471
|
-
} catch { /* typing 失败不影响回复 */ }
|
|
472
|
-
|
|
473
|
-
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
474
|
-
|
|
475
|
-
try {
|
|
476
|
-
// 使用 continue 获取流式响应
|
|
477
|
-
const result = await agent.sendMessage(text, {
|
|
478
|
-
sessionId: sessionId,
|
|
479
|
-
priority: 1,
|
|
480
|
-
});
|
|
481
|
-
const errors=result.chunks.filter(a=>a.type==='error').map(a=>a.error)
|
|
482
|
-
if(errors.length){
|
|
483
|
-
throw new Error(errors.join('\n'))
|
|
484
|
-
}
|
|
485
|
-
if(result.content){
|
|
486
|
-
await this._sendMessageBatch(originalMsg, userId, result.content, true)
|
|
487
|
-
}else{
|
|
488
|
-
const msg=`继续进行下一步`
|
|
489
|
-
await this._sendMessageBatch(originalMsg, userId, msg, true)
|
|
490
|
-
agent.sendMessage(msg,{sessionId,priority: 1})
|
|
467
|
+
|
|
468
|
+
async _save_file(msg){
|
|
469
|
+
const files=[]
|
|
470
|
+
try{
|
|
471
|
+
const file_list=msg?.raw?.item_list||[]
|
|
472
|
+
for(const item of file_list){
|
|
473
|
+
const file_item=item[`${msg.type}_item`]
|
|
474
|
+
const url=file_item?.media?.full_url||null
|
|
475
|
+
const aesKey=file_item?.media?.aes_key||null
|
|
476
|
+
if(url){
|
|
477
|
+
const file=await this.downloader.fromWeXin(url,aesKey)
|
|
478
|
+
files.push(file.path)
|
|
479
|
+
}
|
|
480
|
+
|
|
491
481
|
}
|
|
492
|
-
}
|
|
493
|
-
log
|
|
494
|
-
|
|
482
|
+
}catch(err){
|
|
483
|
+
console.log(err)
|
|
484
|
+
}
|
|
485
|
+
finally{
|
|
486
|
+
return files
|
|
495
487
|
}
|
|
496
488
|
}
|
|
497
489
|
|
|
490
|
+
|
|
498
491
|
/**
|
|
499
492
|
* 处理对话
|
|
500
493
|
*/
|
|
@@ -513,27 +506,31 @@ class WeixinPlugin extends Plugin {
|
|
|
513
506
|
} catch { /* typing 失败不影响回复 */ }
|
|
514
507
|
|
|
515
508
|
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
516
|
-
|
|
509
|
+
const sessionScope = agent.createSessionScope(sessionId);
|
|
517
510
|
try {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
})
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
511
|
+
// 使用事件方式实时处理流式响应
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
sessionScope.on('message:complete', async ({content}) => {
|
|
515
|
+
if(content){
|
|
516
|
+
await this._sendMessageBatch(originalMsg, userId, content, true)
|
|
517
|
+
}else{
|
|
518
|
+
const msg = `继续进行下一步`
|
|
519
|
+
await this._sendMessageBatch(originalMsg, userId, msg, true)
|
|
520
|
+
agent.sendMessage(msg, { sessionId, priority: 1 })
|
|
521
|
+
}
|
|
522
|
+
})
|
|
523
|
+
sessionScope.on('message:error', async ({error}) => {
|
|
524
|
+
await this._sendMessageBatch(originalMsg, userId, error, true)
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
const result=await agent.sendMessage(text, { sessionId, priority: 1 })
|
|
533
528
|
|
|
534
529
|
} catch (err) {
|
|
535
530
|
log.error(' Chat error:', err.message)
|
|
536
531
|
await this._sendMessageBatch(originalMsg, userId, `发生错误:${err.message}`, true)
|
|
532
|
+
}finally{
|
|
533
|
+
sessionScope.removeAllListeners()
|
|
537
534
|
}
|
|
538
535
|
}
|
|
539
536
|
|