foliko 1.0.15 → 1.0.17
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/.claude/settings.local.json +9 -1
- package/package.json +3 -5
- package/plugins/weixin-plugin.js +52 -25
|
@@ -47,7 +47,15 @@
|
|
|
47
47
|
"Bash(npx tsc:*)",
|
|
48
48
|
"Bash(node --check /d/Code/vb-agent/plugins/weixin-plugin.js 2>&1)",
|
|
49
49
|
"Bash(node --check /d/Code/vb-agent/plugins/telegram-plugin.js && node --check /d/Code/vb-agent/plugins/weixin-plugin.js && echo \"OK\")",
|
|
50
|
-
"Bash(node --check /d/Code/vb-agent/cli/src/ui/chat-ui.js && echo \"OK\")"
|
|
50
|
+
"Bash(node --check /d/Code/vb-agent/cli/src/ui/chat-ui.js && echo \"OK\")",
|
|
51
|
+
"Bash(npm uninstall:*)",
|
|
52
|
+
"Bash(rm -rf /tmp/weixin-bot && git clone https://github.com/chnak/weixin-bot.git /tmp/weixin-bot 2>&1)",
|
|
53
|
+
"Bash(mkdir -p node_modules/@pinixai/weixin-bot && cp -r /tmp/weixin-bot/nodejs/* node_modules/@pinixai/weixin-bot/ && cd node_modules/@pinixai/weixin-bot && npm install 2>&1)",
|
|
54
|
+
"Bash(node --check /d/Code/vb-agent/plugins/weixin-plugin.js && echo \"OK\")",
|
|
55
|
+
"Bash(node -e \"import\\('@pinixai/weixin-bot'\\).then\\(m => console.log\\('OK:', Object.keys\\(m\\)\\)\\).catch\\(e => console.error\\('Error:', e.message\\)\\)\")",
|
|
56
|
+
"Bash(npm run:*)",
|
|
57
|
+
"Bash(node -e \"const { WeixinBot } = require\\('@pinixai/weixin-bot'\\); console.log\\(typeof WeixinBot\\)\" 2>&1)",
|
|
58
|
+
"Bash(node -e \"import\\('@pinixai/weixin-bot'\\).then\\(m => console.log\\('OK:', typeof m.WeixinBot\\)\\).catch\\(e => console.error\\('Error:', e.message\\)\\)\" 2>&1)"
|
|
51
59
|
]
|
|
52
60
|
}
|
|
53
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foliko",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "简约的插件化 Agent 框架",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@ai-sdk/openai-compatible": "^2.0.35",
|
|
27
27
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
29
|
-
"@pinixai/weixin-bot": "
|
|
29
|
+
"@pinixai/weixin-bot": "github:chnak/weixin-bot",
|
|
30
30
|
"ai": "^6.0.116",
|
|
31
31
|
"dotenv": "^17.3.1",
|
|
32
32
|
"imap": "^0.8.19",
|
|
@@ -37,9 +37,7 @@
|
|
|
37
37
|
"node-telegram-bot-api": "^0.67.0",
|
|
38
38
|
"nodemailer": "^6.10.0",
|
|
39
39
|
"qrcode-terminal": "^0.12.0",
|
|
40
|
+
"weixin-bot": "github:chnak/weixin-bot",
|
|
40
41
|
"zod": "^3.24.0"
|
|
41
|
-
},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"typescript": "^5.9.3"
|
|
44
42
|
}
|
|
45
43
|
}
|
package/plugins/weixin-plugin.js
CHANGED
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
const { Plugin } = require('../src/core/plugin-base')
|
|
11
11
|
const { z } = require('zod')
|
|
12
|
-
const path = require('path')
|
|
13
|
-
const fs = require('fs')
|
|
14
12
|
|
|
15
13
|
module.exports = function(Plugin) {
|
|
16
14
|
return class WeixinPlugin extends Plugin {
|
|
@@ -57,30 +55,7 @@ module.exports = function(Plugin) {
|
|
|
57
55
|
return this
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
async _checkAndBuild() {
|
|
61
|
-
// 检查 dist 目录是否存在
|
|
62
|
-
const weixinBotPkg = path.join(__dirname, '..', '..', 'node_modules', '@pinixai', 'weixin-bot', 'package.json')
|
|
63
|
-
const pkgDir = path.dirname(weixinBotPkg)
|
|
64
|
-
const distPath = path.join(pkgDir, 'dist', 'index.js')
|
|
65
|
-
|
|
66
|
-
if (!fs.existsSync(distPath)) {
|
|
67
|
-
console.log('[WeChat] Building @pinixai/weixin-bot...')
|
|
68
|
-
const { execSync } = require('child_process')
|
|
69
|
-
try {
|
|
70
|
-
execSync('npx tsc', {
|
|
71
|
-
cwd: pkgDir,
|
|
72
|
-
stdio: 'inherit',
|
|
73
|
-
timeout: 60000
|
|
74
|
-
})
|
|
75
|
-
console.log('[WeChat] Build complete')
|
|
76
|
-
} catch (err) {
|
|
77
|
-
console.warn('[WeChat] Build failed:', err.message)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
58
|
async _initBotAsync() {
|
|
83
|
-
await this._checkAndBuild()
|
|
84
59
|
|
|
85
60
|
let WeixinBot
|
|
86
61
|
try {
|
|
@@ -121,11 +96,63 @@ module.exports = function(Plugin) {
|
|
|
121
96
|
await this._handleMessage(msg)
|
|
122
97
|
})
|
|
123
98
|
|
|
99
|
+
// 监听定时提醒事件
|
|
100
|
+
if (this._framework) {
|
|
101
|
+
this._framework.on('scheduler:reminder', async (data) => {
|
|
102
|
+
console.log('[WeChat] Received scheduler reminder:', data)
|
|
103
|
+
await this._handleScheduledReminder(data)
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
124
107
|
// 启动Bot
|
|
125
108
|
await this._bot.run()
|
|
126
109
|
console.log('[WeChat] 开始接收微信消息')
|
|
127
110
|
}
|
|
128
111
|
|
|
112
|
+
/**
|
|
113
|
+
* 处理定时提醒
|
|
114
|
+
*/
|
|
115
|
+
async _handleScheduledReminder(data) {
|
|
116
|
+
const { taskName, message, sessionId } = data
|
|
117
|
+
|
|
118
|
+
// 构建提醒消息
|
|
119
|
+
const reminderText = `🔔 [${taskName}]\n\n${message}`
|
|
120
|
+
|
|
121
|
+
// 如果有 sessionId 是 weixin 类型的,发送到对应用户
|
|
122
|
+
if (sessionId && sessionId.startsWith('weixin_')) {
|
|
123
|
+
const userId = sessionId.replace('weixin_', '')
|
|
124
|
+
try {
|
|
125
|
+
await this._bot.send(userId, reminderText)
|
|
126
|
+
console.log(`[WeChat] Reminder sent to user ${userId}`)
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.error(`[WeChat] Failed to send reminder:`, err.message)
|
|
129
|
+
}
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 其他情况(包括 null 或其他 sessionId),发送到最近的 Weixin 会话
|
|
134
|
+
if (this._sessionPlugin) {
|
|
135
|
+
const allSessions = this._sessionPlugin.listSessions()
|
|
136
|
+
const weixinSessions = allSessions
|
|
137
|
+
.filter(s => s.id.startsWith('weixin_'))
|
|
138
|
+
.sort((a, b) => new Date(b.lastActive).getTime() - new Date(a.lastActive).getTime())
|
|
139
|
+
|
|
140
|
+
if (weixinSessions.length > 0) {
|
|
141
|
+
const userId = weixinSessions[0].id.replace('weixin_', '')
|
|
142
|
+
try {
|
|
143
|
+
await this._bot.send(userId, reminderText)
|
|
144
|
+
console.log(`[WeChat] Reminder sent to user ${userId}`)
|
|
145
|
+
} catch (err) {
|
|
146
|
+
console.error(`[WeChat] Failed to send reminder to ${userId}:`, err.message)
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
console.log('[WeChat] No active WeChat sessions to send reminder')
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
console.log('[WeChat] No active WeChat sessions to send reminder')
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
129
156
|
/**
|
|
130
157
|
* 拦截 SDK 的 stderr 输出,渲染二维码到终端
|
|
131
158
|
*/
|