foliko 1.0.85 → 1.0.87

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.
Files changed (178) hide show
  1. package/.agent/agents/code-assistant.json +14 -0
  2. package/.agent/agents/email-assistant.json +14 -0
  3. package/.agent/agents/file-assistant.json +15 -0
  4. package/.agent/agents/system-assistant.json +15 -0
  5. package/.agent/agents/web-assistant.json +12 -0
  6. package/.agent/data/ambient/goals.json +50 -0
  7. package/.agent/data/ambient/memories.json +7 -0
  8. package/.agent/data/default.json +21 -311
  9. package/.agent/data/plugins-state.json +162 -174
  10. package/.agent/data/scheduler/tasks.json +1 -0
  11. package/.agent/data/weixin.json +6 -0
  12. package/.agent/mcp_config.json +1 -0
  13. package/.agent/package.json +8 -0
  14. package/.agent/plugins/__pycache__/test_plugin.cpython-312.pyc +0 -0
  15. package/.agent/plugins/daytona/README.md +89 -0
  16. package/.agent/plugins/daytona/index.js +377 -0
  17. package/.agent/plugins/daytona/package.json +12 -0
  18. package/.agent/plugins/marknative/README.md +134 -0
  19. package/.agent/plugins/marknative/index.js +228 -0
  20. package/.agent/plugins/marknative/package.json +12 -0
  21. package/.agent/plugins/marknative/update-readme.js +134 -0
  22. package/.agent/plugins/system-info/index.js +387 -0
  23. package/.agent/plugins/system-info/package.json +4 -0
  24. package/.agent/plugins/system-info/test.js +40 -0
  25. package/.agent/plugins/temp-repo/LICENSE +201 -0
  26. package/.agent/plugins/test_plugin.py +304 -0
  27. package/.agent/plugins.json +14 -5
  28. package/.agent/python-scripts/test_sample.py +24 -0
  29. package/.agent/skills/agent-browser/SKILL.md +311 -0
  30. package/.agent/skills/agent-browser/TEST_PLAN.md +200 -0
  31. package/.agent/skills/sysinfo/SKILL.md +38 -0
  32. package/.agent/skills/sysinfo/system-info.sh +130 -0
  33. package/.agent/skills/workflow/SKILL.md +324 -0
  34. package/.agent/workflows/email-digest.json +50 -0
  35. package/.agent/workflows/file-backup.json +21 -0
  36. package/.agent/workflows/get-ip-notify.json +32 -0
  37. package/.agent/workflows/news-aggregator.json +93 -0
  38. package/.agent/workflows/news-dashboard-v2.json +94 -0
  39. package/.agent/workflows/notification-batch.json +32 -0
  40. package/.claude/settings.local.json +8 -7
  41. package/.env.example +56 -56
  42. package/README.md +441 -441
  43. package/examples/test-chat-debug.js +102 -0
  44. package/examples/test-chat-result.js +76 -0
  45. package/examples/test-chat-stream-diff.js +63 -0
  46. package/examples/test-concurrent-chat.js +60 -0
  47. package/examples/test-long-chat.js +77 -0
  48. package/examples/test-session-chat.js +93 -0
  49. package/package.json +2 -2
  50. package/plugins/ambient-agent/EventWatcher.js +4 -4
  51. package/plugins/extension-executor-plugin.js +44 -1
  52. package/plugins/file-system-plugin.js +44 -5
  53. package/plugins/session-plugin.js +21 -0
  54. package/plugins/weixin-plugin.js +278 -29
  55. package/skills/find-skills/AGENTS.md +162 -162
  56. package/skills/find-skills/SKILL.md +133 -133
  57. package/skills/foliko-dev/SKILL.md +67 -0
  58. package/skills/python-plugin-dev/SKILL.md +238 -238
  59. package/src/core/agent-chat.js +106 -58
  60. package/src/core/agent.js +3 -61
  61. package/src/utils/index.js +1 -1
  62. package/.agent/.shared/ui-ux-pro-max/data/charts.csv +0 -26
  63. package/.agent/.shared/ui-ux-pro-max/data/colors.csv +0 -97
  64. package/.agent/.shared/ui-ux-pro-max/data/icons.csv +0 -101
  65. package/.agent/.shared/ui-ux-pro-max/data/landing.csv +0 -31
  66. package/.agent/.shared/ui-ux-pro-max/data/products.csv +0 -97
  67. package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +0 -24
  68. package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +0 -45
  69. package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +0 -53
  70. package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +0 -56
  71. package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +0 -53
  72. package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +0 -53
  73. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +0 -51
  74. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +0 -59
  75. package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +0 -52
  76. package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +0 -54
  77. package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +0 -61
  78. package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +0 -54
  79. package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +0 -51
  80. package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +0 -50
  81. package/.agent/.shared/ui-ux-pro-max/data/styles.csv +0 -59
  82. package/.agent/.shared/ui-ux-pro-max/data/typography.csv +0 -58
  83. package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +0 -101
  84. package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +0 -100
  85. package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +0 -31
  86. package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
  87. package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
  88. package/.agent/.shared/ui-ux-pro-max/scripts/core.py +0 -258
  89. package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +0 -1067
  90. package/.agent/.shared/ui-ux-pro-max/scripts/search.py +0 -106
  91. package/.agent/ARCHITECTURE.md +0 -288
  92. package/.agent/agents/ambient-agent.md +0 -57
  93. package/.agent/agents/debugger.md +0 -55
  94. package/.agent/agents/email-assistant.md +0 -49
  95. package/.agent/agents/file-manager.md +0 -42
  96. package/.agent/agents/python-developer.md +0 -60
  97. package/.agent/agents/scheduler.md +0 -59
  98. package/.agent/agents/web-developer.md +0 -45
  99. package/.agent/data/puppeteer-sessions/undefined.json +0 -6
  100. package/.agent/mcp_config_updated.json +0 -12
  101. package/.agent/rules/GEMINI.md +0 -273
  102. package/.agent/rules/allow-rule.md +0 -77
  103. package/.agent/rules/log-rule.md +0 -83
  104. package/.agent/rules/security-rule.md +0 -93
  105. package/.agent/scripts/auto_preview.py +0 -148
  106. package/.agent/scripts/checklist.py +0 -217
  107. package/.agent/scripts/session_manager.py +0 -120
  108. package/.agent/scripts/verify_all.py +0 -327
  109. package/.agent/skills/api-patterns/SKILL.md +0 -81
  110. package/.agent/skills/api-patterns/api-style.md +0 -42
  111. package/.agent/skills/api-patterns/auth.md +0 -24
  112. package/.agent/skills/api-patterns/documentation.md +0 -26
  113. package/.agent/skills/api-patterns/graphql.md +0 -41
  114. package/.agent/skills/api-patterns/rate-limiting.md +0 -31
  115. package/.agent/skills/api-patterns/response.md +0 -37
  116. package/.agent/skills/api-patterns/rest.md +0 -40
  117. package/.agent/skills/api-patterns/scripts/api_validator.py +0 -211
  118. package/.agent/skills/api-patterns/security-testing.md +0 -122
  119. package/.agent/skills/api-patterns/trpc.md +0 -41
  120. package/.agent/skills/api-patterns/versioning.md +0 -22
  121. package/.agent/skills/app-builder/SKILL.md +0 -75
  122. package/.agent/skills/app-builder/agent-coordination.md +0 -71
  123. package/.agent/skills/app-builder/feature-building.md +0 -53
  124. package/.agent/skills/app-builder/project-detection.md +0 -34
  125. package/.agent/skills/app-builder/scaffolding.md +0 -118
  126. package/.agent/skills/app-builder/tech-stack.md +0 -40
  127. package/.agent/skills/app-builder/templates/SKILL.md +0 -39
  128. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +0 -76
  129. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +0 -92
  130. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +0 -88
  131. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +0 -88
  132. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +0 -83
  133. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +0 -90
  134. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +0 -90
  135. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +0 -122
  136. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +0 -122
  137. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +0 -169
  138. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +0 -134
  139. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +0 -83
  140. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +0 -119
  141. package/.agent/skills/architecture/SKILL.md +0 -55
  142. package/.agent/skills/architecture/context-discovery.md +0 -43
  143. package/.agent/skills/architecture/examples.md +0 -94
  144. package/.agent/skills/architecture/pattern-selection.md +0 -68
  145. package/.agent/skills/architecture/patterns-reference.md +0 -50
  146. package/.agent/skills/architecture/trade-off-analysis.md +0 -77
  147. package/.agent/skills/clean-code/SKILL.md +0 -201
  148. package/.agent/skills/doc.md +0 -177
  149. package/.agent/skills/frontend-design/SKILL.md +0 -418
  150. package/.agent/skills/frontend-design/animation-guide.md +0 -331
  151. package/.agent/skills/frontend-design/color-system.md +0 -311
  152. package/.agent/skills/frontend-design/decision-trees.md +0 -418
  153. package/.agent/skills/frontend-design/motion-graphics.md +0 -306
  154. package/.agent/skills/frontend-design/scripts/accessibility_checker.py +0 -183
  155. package/.agent/skills/frontend-design/scripts/ux_audit.py +0 -722
  156. package/.agent/skills/frontend-design/typography-system.md +0 -345
  157. package/.agent/skills/frontend-design/ux-psychology.md +0 -1116
  158. package/.agent/skills/frontend-design/visual-effects.md +0 -383
  159. package/.agent/skills/i18n-localization/SKILL.md +0 -154
  160. package/.agent/skills/i18n-localization/scripts/i18n_checker.py +0 -241
  161. package/.agent/skills/mcp-builder/SKILL.md +0 -176
  162. package/.agent/skills/web-design-guidelines/SKILL.md +0 -57
  163. package/.agent/workflows/brainstorm.md +0 -113
  164. package/.agent/workflows/create.md +0 -59
  165. package/.agent/workflows/debug.md +0 -103
  166. package/.agent/workflows/deploy.md +0 -176
  167. package/.agent/workflows/enhance.md +0 -63
  168. package/.agent/workflows/orchestrate.md +0 -237
  169. package/.agent/workflows/plan.md +0 -89
  170. package/.agent/workflows/preview.md +0 -81
  171. package/.agent/workflows/simple-test.md +0 -42
  172. package/.agent/workflows/status.md +0 -86
  173. package/.agent/workflows/structured-orchestrate.md +0 -180
  174. package/.agent/workflows/test.md +0 -144
  175. package/.agent/workflows/ui-ux-pro-max.md +0 -296
  176. /package/.agent/plugins/{puppeteer-plugin → temp-repo/puppeteer-plugin}/README.md +0 -0
  177. /package/.agent/plugins/{puppeteer-plugin → temp-repo/puppeteer-plugin}/index.js +0 -0
  178. /package/.agent/plugins/{puppeteer-plugin → temp-repo/puppeteer-plugin}/package.json +0 -0
@@ -14,6 +14,8 @@ const {cleanResponse} =require('../src/utils')
14
14
  const removeMarkdown = require('remove-markdown');
15
15
  const { z } = require('zod')
16
16
  const { WeixinBot } = require('@chnak/weixin-bot')
17
+ const fs = require('fs')
18
+ const path = require('path')
17
19
 
18
20
  class WeixinPlugin extends Plugin {
19
21
  constructor(config = {}) {
@@ -26,7 +28,7 @@ class WeixinPlugin extends Plugin {
26
28
  this.enabled = false
27
29
  this.path=`.agent/data`
28
30
  this.systemPrompt=`你是一个微信助手。
29
-
31
+
30
32
  **重要:** 子Agent 匹配规则必须遵守:
31
33
  - 根据【子 Agent 匹配表】,将任务委托给最匹配的子Agent处理
32
34
  - 使用 subagent_call 工具并指定 agentName 来委托任务
@@ -45,6 +47,7 @@ class WeixinPlugin extends Plugin {
45
47
 
46
48
  this._framework = null
47
49
  this._bot = null
50
+ this._myUserId = null // 机器人自己的 userId
48
51
  this._sessionPlugin = null
49
52
  this._sessionDeleteHandler = null
50
53
  this._sessionAgents = new Map() // userId -> Agent
@@ -55,9 +58,190 @@ class WeixinPlugin extends Plugin {
55
58
 
56
59
  install(framework) {
57
60
  this._framework = framework
61
+ // 注册微信发送工具
62
+ this._registerTools()
58
63
  return this
59
64
  }
60
65
 
66
+ /**
67
+ * 注册微信发送工具(发送给自己)
68
+ */
69
+ _registerTools() {
70
+ // 发送文本消息给自己
71
+ this.registerTool({
72
+ name: 'weixin_send_message',
73
+ description: '发送文本消息到微信(发给登录的账号)',
74
+ inputSchema: z.object({
75
+ message: z.string().describe('要发送的文本内容')
76
+ }),
77
+ execute: async (args) => {
78
+ return this._sendMessage(args.message)
79
+ }
80
+ })
81
+
82
+ // 发送图片给自己
83
+ this.registerTool({
84
+ name: 'weixin_send_image',
85
+ description: '发送图片到微信(发给登录的账号)',
86
+ inputSchema: z.object({
87
+ imagePath: z.string().describe('本地图片文件路径')
88
+ }),
89
+ execute: async (args) => {
90
+ return this._sendImage(args.imagePath)
91
+ }
92
+ })
93
+
94
+ // 发送文件给自己
95
+ this.registerTool({
96
+ name: 'weixin_send_file',
97
+ description: '发送文件到微信(发给登录的账号)',
98
+ inputSchema: z.object({
99
+ filePath: z.string().describe('本地文件路径'),
100
+ fileName: z.string().optional().describe('文件名(可选,默认从路径推断)')
101
+ }),
102
+ execute: async (args) => {
103
+ return this._sendFile(args.filePath, args.fileName)
104
+ }
105
+ })
106
+
107
+ // 发送视频给自己
108
+ this.registerTool({
109
+ name: 'weixin_send_video',
110
+ description: '发送视频到微信(发给登录的账号)',
111
+ inputSchema: z.object({
112
+ videoPath: z.string().describe('本地视频文件路径'),
113
+ playLength: z.number().optional().describe('视频时长(秒)')
114
+ }),
115
+ execute: async (args) => {
116
+ return this._sendVideo(args.videoPath, args.playLength)
117
+ }
118
+ })
119
+
120
+ // 发送语音给自己
121
+ this.registerTool({
122
+ name: 'weixin_send_voice',
123
+ description: '发送语音到微信(发给登录的账号,silk格式)',
124
+ inputSchema: z.object({
125
+ voicePath: z.string().describe('本地语音文件路径(silk格式)')
126
+ }),
127
+ execute: async (args) => {
128
+ return this._sendVoice(args.voicePath)
129
+ }
130
+ })
131
+ }
132
+
133
+ /**
134
+ * 发送图片给自己
135
+ */
136
+ async _sendImage(imagePath) {
137
+ if (!this._bot) {
138
+ return { error: '微信机器人未连接' }
139
+ }
140
+ if (!this._myUserId) {
141
+ return { error: '未记录机器人用户ID' }
142
+ }
143
+ try {
144
+ if (!fs.existsSync(imagePath)) {
145
+ return { error: `文件不存在: ${imagePath}` }
146
+ }
147
+ await this._bot.sendImage(this._myUserId, imagePath)
148
+ // log.info(` 图片发送成功: ${path.basename(imagePath)}`)
149
+ return { success: true, message: '图片发送成功' }
150
+ } catch (err) {
151
+ log.error(` 图片发送失败: ${err.message}`)
152
+ return { error: err.message }
153
+ }
154
+ }
155
+
156
+ /**
157
+ * 发送文件给自己
158
+ */
159
+ async _sendFile(filePath, fileName) {
160
+ if (!this._bot) {
161
+ return { error: '微信机器人未连接' }
162
+ }
163
+ if (!this._myUserId) {
164
+ return { error: '未记录机器人用户ID' }
165
+ }
166
+ try {
167
+ if (!fs.existsSync(filePath)) {
168
+ return { error: `文件不存在: ${filePath}` }
169
+ }
170
+ await this._bot.sendFile(this._myUserId, filePath, fileName)
171
+ // log.info(` 文件发送成功: ${fileName || path.basename(filePath)}`)
172
+ return { success: true, message: '文件发送成功' }
173
+ } catch (err) {
174
+ log.error(` 文件发送失败: ${err.message}`)
175
+ return { error: err.message }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * 发送视频给自己
181
+ */
182
+ async _sendVideo(videoPath, playLength) {
183
+ if (!this._bot) {
184
+ return { error: '微信机器人未连接' }
185
+ }
186
+ if (!this._myUserId) {
187
+ return { error: '未记录机器人用户ID' }
188
+ }
189
+ try {
190
+ if (!fs.existsSync(videoPath)) {
191
+ return { error: `文件不存在: ${videoPath}` }
192
+ }
193
+ const opts = playLength ? { playLength } : {}
194
+ await this._bot.sendVideo(this._myUserId, videoPath, opts)
195
+ // log.info(` 视频发送成功: ${path.basename(videoPath)}`)
196
+ return { success: true, message: '视频发送成功' }
197
+ } catch (err) {
198
+ log.error(` 视频发送失败: ${err.message}`)
199
+ return { error: err.message }
200
+ }
201
+ }
202
+
203
+ /**
204
+ * 发送语音给自己
205
+ */
206
+ async _sendVoice(voicePath) {
207
+ if (!this._bot) {
208
+ return { error: '微信机器人未连接' }
209
+ }
210
+ if (!this._myUserId) {
211
+ return { error: '未记录机器人用户ID' }
212
+ }
213
+ try {
214
+ if (!fs.existsSync(voicePath)) {
215
+ return { error: `文件不存在: ${voicePath}` }
216
+ }
217
+ await this._bot.sendVoice(this._myUserId, voicePath)
218
+ // log.info(` 语音发送成功: ${path.basename(voicePath)}`)
219
+ return { success: true, message: '语音发送成功' }
220
+ } catch (err) {
221
+ log.error(` 语音发送失败: ${err.message}`)
222
+ return { error: err.message }
223
+ }
224
+ }
225
+
226
+ /**
227
+ * 发送文本消息给自己
228
+ */
229
+ async _sendMessage(message) {
230
+ if (!this._bot) {
231
+ return { error: '微信机器人未连接' }
232
+ }
233
+ if (!this._myUserId) {
234
+ return { error: '未记录机器人用户ID' }
235
+ }
236
+ try {
237
+ await this._bot.send(this._myUserId, message)
238
+ return { success: true, message: '消息发送成功' }
239
+ } catch (err) {
240
+ log.error(` 消息发送失败: ${err.message}`)
241
+ return { error: err.message }
242
+ }
243
+ }
244
+
61
245
  async start(framework) {
62
246
  // 防止重复初始化
63
247
  if (this._initialized) return this
@@ -71,7 +255,7 @@ class WeixinPlugin extends Plugin {
71
255
  this._sessionDeleteHandler = (sessionId) => {
72
256
  // 只处理 weixin 会话的删除
73
257
  if (sessionId.startsWith('weixin_')) {
74
- log.info(` Session deleted: ${sessionId}`)
258
+ // log.info(` Session deleted: ${sessionId}`)
75
259
  }
76
260
  }
77
261
  this._sessionPlugin.on('session:deleted', this._sessionDeleteHandler)
@@ -80,19 +264,19 @@ class WeixinPlugin extends Plugin {
80
264
  // 监听定时提醒事件
81
265
  if (this._framework) {
82
266
  this._framework.on('scheduler:reminder', async (data) => {
83
- log.info(' Received scheduler reminder:', data)
267
+ // log.info(' Received scheduler reminder:', data)
84
268
  await this._handleScheduledReminder(data)
85
269
  })
86
270
 
87
271
  // 监听 webhook 事件
88
272
  this._framework.on('webhook:received', async (data) => {
89
- log.info(' Received webhook event:', data)
273
+ // log.info(' Received webhook event:', data)
90
274
  await this._handleWebhookNotification(data)
91
275
  })
92
276
 
93
277
  // 监听统一通知事件
94
278
  this._framework.on('notification', async (data) => {
95
- log.info(' Received notification:', data)
279
+ // log.info(' Received notification:', data)
96
280
  await this._handleNotification(data)
97
281
  })
98
282
  }
@@ -119,17 +303,21 @@ class WeixinPlugin extends Plugin {
119
303
  this._bot = new WeixinBot({
120
304
  tokenPath:`${this.path}/${this.name}.json`,
121
305
  onError: (err) => {
122
- log.error(' Error:', err instanceof Error ? err.stack ?? err.message : String(err))
306
+ log.error(' Error:', err.message)
123
307
  },
124
308
  })
125
309
 
126
310
  const loginOptions = { force: this.config.forceLogin }
127
- log.info('', this.config.forceLogin ? '强制重新扫码登录...' : '正在登录(已有凭证则自动跳过扫码)...')
311
+ // log.info('', this.config.forceLogin ? '强制重新扫码登录...' : '正在登录(已有凭证则自动跳过扫码)...')
128
312
 
129
313
  const creds = await this._bot.login(loginOptions)
130
- log.info(' 登录成功 — Bot ID:', creds.accountId)
131
- log.info(' 关联用户:', creds.userId)
132
- log.info(' API 地址:', creds.baseUrl)
314
+ // log.info(' 登录成功 — Bot ID:', creds.accountId)
315
+ // log.info(' 关联用户:', creds.userId)
316
+ // log.info(' API 地址:', creds.baseUrl)
317
+
318
+ // 记录机器人自己的 userId(用于发送媒体)
319
+ this._myUserId = creds.userId
320
+ // log.info(' 已记录机器人 userId:', this._myUserId)
133
321
 
134
322
  // 注册消息处理
135
323
  this._bot.onMessage(async (msg) => {
@@ -138,7 +326,7 @@ class WeixinPlugin extends Plugin {
138
326
 
139
327
  // 启动Bot
140
328
  await this._bot.run()
141
- log.info(' 开始接收微信消息')
329
+ // log.info(' 开始接收微信消息')
142
330
  }
143
331
 
144
332
  /**
@@ -180,7 +368,7 @@ class WeixinPlugin extends Plugin {
180
368
  // 检查缓存
181
369
  if (this._sessionAgents.has(userId)) {
182
370
  const agent = this._sessionAgents.get(userId)
183
- log.info(' Reusing cached session agent for userId:', userId)
371
+ // log.info(' Reusing cached session agent for userId:', userId)
184
372
  return { agent, sessionId: `weixin_${userId}` }
185
373
  }
186
374
 
@@ -191,7 +379,7 @@ class WeixinPlugin extends Plugin {
191
379
  metadata: { WORK_DIR: process.cwd() }
192
380
  })
193
381
  this._sessionAgents.set(userId, agent)
194
- log.info(' Created new session agent for userId:', userId)
382
+ // log.info(' Created new session agent for userId:', userId)
195
383
 
196
384
  // 使用 SessionPlugin 管理会话历史
197
385
  if (this._sessionPlugin) {
@@ -201,7 +389,7 @@ class WeixinPlugin extends Plugin {
201
389
  })
202
390
  }
203
391
 
204
- log.info(` Session ready for user: ${userId}`)
392
+ // log.info(` Session ready for user: ${userId}`)
205
393
  return { agent, sessionId: `weixin_${userId}` }
206
394
  }
207
395
 
@@ -219,17 +407,78 @@ class WeixinPlugin extends Plugin {
219
407
  messageCount = session?.messages?.length || 0
220
408
  }
221
409
 
222
- log.info(` #${messageCount + 1} | 类型: ${msg.type} | 用户: ${userId}`)
223
- log.info(` 内容: ${msg.text}`)
410
+ //log.info(` #${messageCount + 1} | 类型: ${msg.type} | 用户: ${userId}`)
411
+
412
+ // 处理不同类型的消息
413
+ switch (msg.type) {
414
+ case 'text':
415
+ // log.info(` 内容: ${msg.text}`)
416
+ if (msg.text) {
417
+ await this._processChat(userId, msg.text.trim(), msg)
418
+ }
419
+ break
420
+
421
+ case 'image':
422
+ // log.info(` 收到图片消息`)
423
+ await this._processMediaChat(userId, '[用户发送了图片]', msg)
424
+ break
425
+
426
+ case 'file':
427
+ // log.info(` 收到文件消息: ${msg.fileName || 'unknown'}`)
428
+ await this._processMediaChat(userId, `[用户发送了文件: ${msg.fileName || 'unknown'}]`, msg)
429
+ break
430
+
431
+ case 'video':
432
+ // log.info(` 收到视频消息`)
433
+ await this._processMediaChat(userId, '[用户发送了视频]', msg)
434
+ break
435
+
436
+ case 'voice':
437
+ // log.info(` 收到语音消息`)
438
+ await this._processMediaChat(userId, '[用户发送了语音消息]', msg)
439
+ break
440
+
441
+ default:
442
+ // log.info(` 不支持的消息类型: ${msg.type}`)
443
+ if (msg.text) {
444
+ await this._processChat(userId, msg.text.trim(), msg)
445
+ }
446
+ }
447
+ }
224
448
 
225
- // 非文本消息暂不处理
226
- if (msg.type !== 'text' || !msg.text) {
227
- log.info(' Unsupported message type or no text')
449
+ /**
450
+ * 处理媒体消息(图片/文件/视频/语音)
451
+ */
452
+ async _processMediaChat(userId, text, originalMsg) {
453
+ const sessionInfo = this._getSessionAgent(userId)
454
+ if (!sessionInfo) {
455
+ log.error(' No session agent available')
228
456
  return
229
457
  }
230
458
 
231
- const text = msg.text.trim()
232
- await this._processChat(userId, text, msg)
459
+ const { agent, sessionId } = sessionInfo
460
+
461
+ // 发送正在输入状态
462
+ try {
463
+ await this._bot.sendTyping(userId)
464
+ } catch { /* typing 失败不影响回复 */ }
465
+
466
+ await new Promise((resolve) => setTimeout(resolve, 1000))
467
+
468
+ try {
469
+ const result = await agent.chat(text, {
470
+ sessionId: sessionId
471
+ })
472
+ const fullResponse = cleanResponse(result.message || '')
473
+
474
+ if (fullResponse) {
475
+ await this._sendMessageBatch(originalMsg, userId, fullResponse, true)
476
+ // log.info(` 回复成功 (${fullResponse.length} 字符)`)
477
+ }
478
+ } catch (err) {
479
+ log.error(' Media chat error:', err)
480
+ await this._sendMessageBatch(originalMsg, userId, `发生错误:${err.message}`, true)
481
+ }
233
482
  }
234
483
 
235
484
  /**
@@ -271,13 +520,13 @@ class WeixinPlugin extends Plugin {
271
520
  // 发送回复(超过500字自动分批)
272
521
  if (fullResponse) {
273
522
  await this._sendMessageBatch(originalMsg, userId, fullResponse, true)
274
- log.info(` 回复成功 (${fullResponse.length} 字符)`)
523
+ // log.info(` 回复成功 (${fullResponse.length} 字符)`)
275
524
  } else {
276
525
  await this._sendMessageBatch(originalMsg, userId, '抱歉,我没有收到有效的回复。', true)
277
526
  }
278
527
 
279
528
  } catch (err) {
280
- log.error(' Chat error:', err)
529
+ log.error(' Chat error:', err.message)
281
530
  await this._sendMessageBatch(originalMsg, userId, `发生错误:${err.message}`, true)
282
531
  }
283
532
  }
@@ -317,7 +566,7 @@ class WeixinPlugin extends Plugin {
317
566
  chunks.push(text.slice(i, i + MAX_LEN))
318
567
  }
319
568
 
320
- log.info(` Message too long (${text.length}), splitting into ${chunks.length} parts`)
569
+ // log.info(` Message too long (${text.length}), splitting into ${chunks.length} parts`)
321
570
 
322
571
  for (let i = 0; i < chunks.length; i++) {
323
572
  const chunk = `[${i + 1}/${chunks.length}]\n${chunks[i]}`
@@ -363,7 +612,7 @@ class WeixinPlugin extends Plugin {
363
612
  const userId = sessionId.replace('weixin_', '')
364
613
  try {
365
614
  await this._sendMessageBatch(null, userId, reminderText, false)
366
- log.info(` Reminder sent to user ${userId}`)
615
+ // log.info(` Reminder sent to user ${userId}`)
367
616
  } catch (err) {
368
617
  log.error(` Failed to send reminder:`, err.message)
369
618
  }
@@ -381,7 +630,7 @@ class WeixinPlugin extends Plugin {
381
630
  const userId = weixinSessions[0].id.replace('weixin_', '')
382
631
  try {
383
632
  await this._sendMessageBatch(null, userId, reminderText, false)
384
- log.info(` Reminder sent to recent user ${userId}`)
633
+ // log.info(` Reminder sent to recent user ${userId}`)
385
634
  } catch (err) {
386
635
  log.error(` Failed to send reminder:`, err.message)
387
636
  }
@@ -412,7 +661,7 @@ class WeixinPlugin extends Plugin {
412
661
 
413
662
  try {
414
663
  await this._sendMessageBatch(null, userId, notificationText, false)
415
- log.info(` Webhook notification sent to user ${userId}`)
664
+ // log.info(` Webhook notification sent to user ${userId}`)
416
665
  } catch (err) {
417
666
  log.error(` Failed to send webhook notification:`, err.message)
418
667
  }
@@ -470,7 +719,7 @@ class WeixinPlugin extends Plugin {
470
719
 
471
720
  try {
472
721
  await this._sendMessageBatch(null, userId, notificationText, false)
473
- log.info(` Notification sent to user ${userId}`)
722
+ // log.info(` Notification sent to user ${userId}`)
474
723
  } catch (err) {
475
724
  log.error(` Failed to send notification:`, err.message)
476
725
  }
@@ -511,7 +760,7 @@ class WeixinPlugin extends Plugin {
511
760
  if (this._bot) {
512
761
  this._bot.stop()
513
762
  this._bot = null
514
- log.info(' Bot stopped')
763
+ // log.info(' Bot stopped')
515
764
  }
516
765
  }
517
766