@xpert-ai/plugin-community-wechat 0.1.0

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 (69) hide show
  1. package/README.md +353 -0
  2. package/dist/index.d.ts +20 -0
  3. package/dist/index.js +139 -0
  4. package/dist/lib/constants.d.ts +23 -0
  5. package/dist/lib/constants.js +23 -0
  6. package/dist/lib/conversation-user-key.d.ts +13 -0
  7. package/dist/lib/conversation-user-key.js +28 -0
  8. package/dist/lib/conversation.service.d.ts +215 -0
  9. package/dist/lib/conversation.service.js +1179 -0
  10. package/dist/lib/decorators.d.ts +2 -0
  11. package/dist/lib/decorators.js +3 -0
  12. package/dist/lib/entities/index.d.ts +4 -0
  13. package/dist/lib/entities/index.js +4 -0
  14. package/dist/lib/entities/wechat-personal-account.entity.d.ts +19 -0
  15. package/dist/lib/entities/wechat-personal-account.entity.js +83 -0
  16. package/dist/lib/entities/wechat-personal-conversation-binding.entity.d.ts +14 -0
  17. package/dist/lib/entities/wechat-personal-conversation-binding.entity.js +65 -0
  18. package/dist/lib/entities/wechat-personal-message-log.entity.d.ts +27 -0
  19. package/dist/lib/entities/wechat-personal-message-log.entity.js +108 -0
  20. package/dist/lib/entities/wechat-personal-trigger-binding.entity.d.ts +17 -0
  21. package/dist/lib/entities/wechat-personal-trigger-binding.entity.js +71 -0
  22. package/dist/lib/handoff/index.d.ts +4 -0
  23. package/dist/lib/handoff/index.js +4 -0
  24. package/dist/lib/handoff/wechat-personal-chat-callback.processor.d.ts +26 -0
  25. package/dist/lib/handoff/wechat-personal-chat-callback.processor.js +312 -0
  26. package/dist/lib/handoff/wechat-personal-chat-dispatch.service.d.ts +26 -0
  27. package/dist/lib/handoff/wechat-personal-chat-dispatch.service.js +187 -0
  28. package/dist/lib/handoff/wechat-personal-chat-run-state.service.d.ts +21 -0
  29. package/dist/lib/handoff/wechat-personal-chat-run-state.service.js +39 -0
  30. package/dist/lib/handoff/wechat-personal-chat.types.d.ts +69 -0
  31. package/dist/lib/handoff/wechat-personal-chat.types.js +2 -0
  32. package/dist/lib/message.d.ts +49 -0
  33. package/dist/lib/message.js +64 -0
  34. package/dist/lib/remote-components/wechat-personal-workbench/app.js +1831 -0
  35. package/dist/lib/tokens.d.ts +1 -0
  36. package/dist/lib/tokens.js +1 -0
  37. package/dist/lib/types.d.ts +48 -0
  38. package/dist/lib/types.js +365 -0
  39. package/dist/lib/views/wechat-personal-view.provider.d.ts +17 -0
  40. package/dist/lib/views/wechat-personal-view.provider.js +441 -0
  41. package/dist/lib/wechat-personal-channel.strategy.d.ts +33 -0
  42. package/dist/lib/wechat-personal-channel.strategy.js +197 -0
  43. package/dist/lib/wechat-personal-integration.strategy.d.ts +56 -0
  44. package/dist/lib/wechat-personal-integration.strategy.js +217 -0
  45. package/dist/lib/wechat-personal.client.d.ts +29 -0
  46. package/dist/lib/wechat-personal.client.js +146 -0
  47. package/dist/lib/wechat-personal.controller.d.ts +50 -0
  48. package/dist/lib/wechat-personal.controller.js +270 -0
  49. package/dist/lib/wechat-personal.middleware.d.ts +20 -0
  50. package/dist/lib/wechat-personal.middleware.js +267 -0
  51. package/dist/lib/wechat-personal.plugin.d.ts +2 -0
  52. package/dist/lib/wechat-personal.plugin.js +58 -0
  53. package/dist/lib/wechat-personal.templates.d.ts +2 -0
  54. package/dist/lib/wechat-personal.templates.js +100 -0
  55. package/dist/lib/workflow/index.d.ts +5 -0
  56. package/dist/lib/workflow/index.js +5 -0
  57. package/dist/lib/workflow/wechat-personal-trigger-aggregation.service.d.ts +10 -0
  58. package/dist/lib/workflow/wechat-personal-trigger-aggregation.service.js +39 -0
  59. package/dist/lib/workflow/wechat-personal-trigger-aggregation.types.d.ts +30 -0
  60. package/dist/lib/workflow/wechat-personal-trigger-aggregation.types.js +2 -0
  61. package/dist/lib/workflow/wechat-personal-trigger-flush.processor.d.ts +8 -0
  62. package/dist/lib/workflow/wechat-personal-trigger-flush.processor.js +39 -0
  63. package/dist/lib/workflow/wechat-personal-trigger.strategy.d.ts +65 -0
  64. package/dist/lib/workflow/wechat-personal-trigger.strategy.js +511 -0
  65. package/dist/lib/workflow/wechat-personal-trigger.types.d.ts +10 -0
  66. package/dist/lib/workflow/wechat-personal-trigger.types.js +2 -0
  67. package/dist/xpert-wechat-personal-admin-assistant.yaml +103 -0
  68. package/dist/xpert-wechat-personal-user-assistant.yaml +127 -0
  69. package/package.json +79 -0
package/README.md ADDED
@@ -0,0 +1,353 @@
1
+ # Personal WeChat wx2.0 Plugin
2
+
3
+ 个人微信 wx2.0 插件用于对接具备 webhook 推送与文本发送接口的 wx2.0 HTTP 服务,将个人微信消息接入 Xpert Agent,并把 Agent 最终文本回复通过 wx2.0 发送回会话。
4
+
5
+ ## 功能概览
6
+
7
+ - 接收 wx2.0 webhook 推送的个人微信消息。
8
+ - 兼容两种入站格式:
9
+ - 全局 webhook:`webhook.allMessagePushUrl` / `AllMsgPushUrl`。
10
+ - 单账号回调:`POST /message/SetCallback?key=<uuid>`。
11
+ - 将消息规范化后派发给绑定的 Xpert Agent。
12
+ - 仅发送 Agent 最终文本回复到微信。
13
+ - 支持 wx2.0 v2 发送接口:`POST /v1/message/sendtext`。
14
+ - 可选回退旧发送接口:`POST /message/SendTextMessage?key=<uuid>`。
15
+ - 提供 Personal WeChat Workbench,用于查看账号、会话、消息日志、配置和运行日志。
16
+ - 提供 Agent middleware tools,用于 assistant 运行时发现 workbench,并辅助查询状态、回调配置、账号和日志。
17
+ - 提供两个 Assistant Template:
18
+ - `wechat-personal-admin-assistant`:管理员模板,用于管理组织内所有个人微信集成。
19
+ - `wechat-personal-user-assistant`:使用者模板,用于接收微信消息并自动回复。
20
+
21
+ ## 消息闭环
22
+
23
+ ```text
24
+ 微信用户
25
+ -> wx2.0
26
+ -> Xpert webhook /api/wechat-personal/webhook/:integrationId
27
+ -> wechat_personal trigger
28
+ -> Xpert Agent
29
+ -> Agent final text
30
+ -> wx2.0 /v1/message/sendtext
31
+ -> 微信用户
32
+ ```
33
+
34
+ 首版只处理文本消息和文本回复,不发送图片、文件、语音,也不把流式 token 实时推送到微信。
35
+
36
+ ## 前置条件
37
+
38
+ 1. wx2.0 服务已启动,并且 Xpert 后端可以访问它的 HTTP 地址。
39
+ 2. Xpert 后端配置了可被 wx2.0 访问的 `API_BASE_URL`。
40
+ 3. 插件已安装并启用。
41
+ 4. 已创建或准备创建一个使用 `wechat-personal-admin-assistant` 或 `wechat-personal-user-assistant` 模板的 Agent。
42
+
43
+ `API_BASE_URL` 很重要。它决定 wx2.0 收到消息后回调到哪里。
44
+
45
+ ```sh
46
+ API_BASE_URL=https://your-xpert-api.example.com
47
+ ```
48
+
49
+ 本机调试时可以是:
50
+
51
+ ```sh
52
+ API_BASE_URL=http://127.0.0.1:3000
53
+ ```
54
+
55
+ 如果 wx2.0 在 Docker 或另一台机器里,不能随便使用 `localhost`,因为 `localhost` 会指向 wx2.0 所在环境本身。
56
+
57
+ ## 创建个人微信集成
58
+
59
+ 在 Xpert 集成配置页选择提供商:
60
+
61
+ ```text
62
+ 个人微信 wx2.0
63
+ ```
64
+
65
+ 字段建议如下。
66
+
67
+ | 字段 | 是否必填 | 建议值 | 说明 |
68
+ | --- | --- | --- | --- |
69
+ | wx2.0 服务地址 | 是 | `http://127.0.0.1:8058` | Xpert 后端主动调用 wx2.0 发消息的地址。生产环境请填写 Xpert 后端可访问的 wx2.0 地址。 |
70
+ | API 版本前缀 | 否 | `/v1/` | 用于拼出发送接口 `{baseUrl}/{apiVersion}message/sendtext`。 |
71
+ | 请求超时(毫秒) | 否 | `10000` | Xpert 调 wx2.0 的 HTTP 超时时间。 |
72
+ | API Token | 否 | 留空 | 仅当 wx2.0 启用 token 校验时填写。插件会作为 `token` header 发送。 |
73
+ | 首选语言 | 否 | `zh-Hans` | 用于默认提示和部分系统回复。 |
74
+ | 回调密钥 | 否 | 留空或随机字符串 | 用于保护 Xpert webhook。填写后回调 URL 会带 `?secret=...`,也支持 `x-wechat-callback-secret` header。 |
75
+ | 群聊触发方式 | 否 | `mention_or_keywords` | 控制群聊中哪些消息会交给 Agent。 |
76
+ | 群聊关键词 | 否 | 如 `小助手`、`客服` | 群聊触发方式包含关键词时使用。 |
77
+ | 忽略自己发出的消息 | 否 | 开启 | 避免自己或机器人发出的消息再次触发 Agent。 |
78
+ | 失败时回退旧发送接口 | 否 | 开启 | `/v1/message/sendtext` 失败时尝试旧接口。 |
79
+
80
+ 最小可用配置:
81
+
82
+ ```text
83
+ wx2.0 服务地址: http://127.0.0.1:8058
84
+ API 版本前缀: /v1/
85
+ 请求超时: 10000
86
+ 首选语言: zh-Hans
87
+ 群聊触发方式: mention_or_keywords
88
+ 忽略自己发出的消息: 开启
89
+ 失败时回退旧发送接口: 开启
90
+ ```
91
+
92
+ 保存后,进入 Personal WeChat Workbench 的账号或配置页面,复制 Xpert webhook URL。
93
+
94
+ 格式类似:
95
+
96
+ ```text
97
+ https://your-xpert-api.example.com/api/wechat-personal/webhook/<integrationId>
98
+ ```
99
+
100
+ 如果配置了回调密钥,格式类似:
101
+
102
+ ```text
103
+ https://your-xpert-api.example.com/api/wechat-personal/webhook/<integrationId>?secret=<callbackSecret>
104
+ ```
105
+
106
+ ## 配置 wx2.0 回调
107
+
108
+ wx2.0 需要把收到的微信消息推送给 Xpert webhook。推荐优先使用全局 webhook。
109
+
110
+ ### 方式一:全局 webhook(推荐)
111
+
112
+ 在 wx2.0 配置中设置:
113
+
114
+ ```text
115
+ webhook.allMessagePushUrl = <Xpert webhook URL>
116
+ ```
117
+
118
+ 或:
119
+
120
+ ```text
121
+ AllMsgPushUrl = <Xpert webhook URL>
122
+ ```
123
+
124
+ 这种方式适合多个账号统一推送。插件会从 payload 中读取 `uuid`、`contactid`、`content`、`sendusername`、`ownerwxid`、`msgtype`、`isself` 等字段。
125
+
126
+ ### 方式二:单账号 SetCallback
127
+
128
+ 如果希望按账号设置回调,可调用 wx2.0 的旧回调接口:
129
+
130
+ ```sh
131
+ curl -X POST "http://127.0.0.1:8058/message/SetCallback?key=<uuid>" \
132
+ -H "Content-Type: application/json" \
133
+ -d '{"CallbackURL":"<Xpert webhook URL>","Enabled":true}'
134
+ ```
135
+
136
+ 其中:
137
+
138
+ - `<uuid>` 是 wx2.0 中该微信账号的 key/uuid。
139
+ - `<Xpert webhook URL>` 是保存集成后得到的 Xpert webhook URL。
140
+
141
+ Workbench 中也提供生成 SetCallback curl 和注册回调的操作。
142
+
143
+ ## 配置 Assistant
144
+
145
+ 插件内置两个模板,按角色选择:
146
+
147
+ ```text
148
+ wechat-personal-admin-assistant
149
+ wechat-personal-user-assistant
150
+ ```
151
+
152
+ ### 管理员模板
153
+
154
+ `wechat-personal-admin-assistant` 面向管理员。它不包含 `wechat_personal` trigger,不会接收或回复微信用户消息。
155
+
156
+ 它包含:
157
+
158
+ - 一个主 Agent:负责排查和管理个人微信运行状态。
159
+ - 一个 `WechatPersonalRuntimeMiddleware`:负责让前端发现 Personal WeChat Workbench,并提供运行时管理工具。
160
+
161
+ 管理员 Workbench 在没有绑定单一集成时,会展示当前组织内所有 `wechat_personal` 集成的运行数据,包括账号、会话、消息、日志、每个集成的 webhook URL 和 SetCallback curl。
162
+
163
+ ### 使用者模板
164
+
165
+ `wechat-personal-user-assistant` 面向最终微信会话回复。它包含:
166
+
167
+ - 一个主 Agent:负责生成自然微信回复。
168
+ - 一个 `wechat_personal` trigger:负责接收个人微信消息并派发给 Agent。
169
+ - 一个 `WechatPersonalRuntimeMiddleware`:负责让前端发现 Personal WeChat Workbench,并提供运行时管理工具。
170
+
171
+ 创建后需要确认两个节点都选择了同一个个人微信集成:
172
+
173
+ 1. `个人微信消息触发器`
174
+ - `integrationId`: 选择刚创建的个人微信集成。
175
+ - `sessionTimeoutSeconds`: 默认 `3600`。
176
+ - `summaryWindowSeconds`: 默认 `0`,表示收到消息立即派发。
177
+ - `groupTriggerMode`: 推荐 `mention_or_keywords`。
178
+ - `groupKeywords`: 按需配置。
179
+
180
+ 2. `Personal WeChat Runtime Tools`
181
+ - `integrationId`: 选择同一个个人微信集成。
182
+
183
+ 发布或启用 Assistant 后,插件会把该集成绑定到当前 Agent。
184
+
185
+ ## 群聊触发方式
186
+
187
+ `groupTriggerMode` 支持:
188
+
189
+ | 值 | 行为 |
190
+ | --- | --- |
191
+ | `mention_or_keywords` | 被 @ 或命中关键词时触发,推荐默认值。 |
192
+ | `mentions` | 仅被 @ 时触发。 |
193
+ | `keywords` | 仅命中关键词时触发。 |
194
+ | `all` | 群聊所有文本消息都触发。谨慎使用。 |
195
+ | `off` | 群聊不触发。 |
196
+
197
+ 群聊触发后,插件会尽量去掉明显的 `@xxx` 前缀,再把正文发给 Agent。
198
+
199
+ ## 会话策略
200
+
201
+ 插件使用如下 conversation key:
202
+
203
+ ```text
204
+ integrationId:uuid:contactId:senderId
205
+ ```
206
+
207
+ 含义:
208
+
209
+ - 私聊:通常 `senderId` 与 `contactId` 一致。
210
+ - 群聊:按 `群 + 发言人` 拆分会话,避免多人共用同一个 Agent conversation。
211
+
212
+ 用户发送:
213
+
214
+ ```text
215
+ /new
216
+ ```
217
+
218
+ 可以重置当前微信会话。也可以在 Workbench 或 middleware tool 中重置指定 conversation binding。
219
+
220
+ ## Workbench
221
+
222
+ Personal WeChat Workbench 通常出现在集成详情页和 Agent workbench 中。
223
+
224
+ 主要页面:
225
+
226
+ - 账号页:查看 wx2.0 账号、在线状态、最近回调、最近回复、错误;复制 webhook;生成 SetCallback curl;启停账号接入。
227
+ - 会话页:查看私聊/群聊会话、绑定的 Agent conversationId,支持重置会话。
228
+ - 消息页:查看入站/出站消息、状态、错误和 payload 摘要,支持重发最后一次 AI 回复。
229
+ - 配置页:查看 wx2.0 baseUrl、apiVersion、token、群聊触发策略、session timeout 等配置摘要。
230
+ - 日志页:查看 webhook、dispatch、Agent callback、wx2.0 sendtext 调用相关记录。
231
+
232
+ ## Agent middleware tools
233
+
234
+ `WechatPersonalRuntimeMiddleware` 暴露以下 Agent middleware tools。它们主要用于运行时管理和诊断,不用于普通微信回复。
235
+
236
+ | Tool | 用途 |
237
+ | --- | --- |
238
+ | `wechat_personal_get_runtime_status` | 查看回调地址、绑定 Agent、账号数、消息数、错误数等运行状态。 |
239
+ | `wechat_personal_get_callback_config` | 获取 Xpert webhook URL 和 SetCallback curl 模板。 |
240
+ | `wechat_personal_list_accounts` | 查询账号列表。 |
241
+ | `wechat_personal_list_conversations` | 查询会话绑定列表。 |
242
+ | `wechat_personal_search_message_logs` | 查询入站、出站、失败、跳过等消息日志。 |
243
+ | `wechat_personal_reset_conversation` | 重置指定会话。 |
244
+ | `wechat_personal_register_callback` | 为指定 wx2.0 账号调用 SetCallback。 |
245
+ | `wechat_personal_set_account_enabled` | 启用或停用指定账号的入站处理。 |
246
+
247
+ 普通微信回复不需要调用这些 tools。Agent 产出的最终回答会由插件 callback processor 自动发送回微信。
248
+
249
+ ## 测试发送
250
+
251
+ 配置完成后,可以用 Xpert helper API 测试 Xpert -> wx2.0 发送链路:
252
+
253
+ ```sh
254
+ curl -X POST "https://your-xpert-api.example.com/api/wechat-personal/<integrationId>/send-text" \
255
+ -H "Content-Type: application/json" \
256
+ -d '{
257
+ "uuid": "<wx2-account-uuid>",
258
+ "contactId": "wxid_xxx",
259
+ "text": "这是一条来自 Xpert 的测试消息"
260
+ }'
261
+ ```
262
+
263
+ 如果发送失败,先检查:
264
+
265
+ - `wx2.0 服务地址` 是否能从 Xpert 后端访问。
266
+ - `apiVersion` 是否为 `/v1/`。
267
+ - wx2.0 是否支持 `/v1/message/sendtext`。
268
+ - 是否需要填写 `API Token`。
269
+ - 是否开启了旧接口回退。
270
+
271
+ ## 常见排障
272
+
273
+ ### wx2.0 能收到微信消息,但 Xpert 没有反应
274
+
275
+ 检查:
276
+
277
+ 1. wx2.0 的全局 webhook 或 SetCallback 是否指向 Xpert webhook URL。
278
+ 2. `API_BASE_URL` 是否是 wx2.0 能访问的地址。
279
+ 3. 如果配置了 `callbackSecret`,wx2.0 回调 URL 是否带了正确的 `?secret=...`。
280
+ 4. Assistant 是否已启用或发布。
281
+ 5. `wechat_personal` trigger 是否选择了正确的 integrationId。
282
+ 6. Workbench 消息日志中是否显示 `skipped` 或 `failed`。
283
+
284
+ ### 私聊能触发,群聊不触发
285
+
286
+ 检查:
287
+
288
+ 1. `groupTriggerMode` 是否为 `mention_or_keywords`、`mentions`、`keywords` 或 `all`。
289
+ 2. 如果使用关键词触发,`groupKeywords` 是否配置了实际会出现的词。
290
+ 3. 群消息是否为空文本、图片、语音或其他暂不支持的媒体消息。
291
+
292
+ ### Agent 回复了,但微信没有收到
293
+
294
+ 检查:
295
+
296
+ 1. `wx2.0 服务地址` 是否正确。
297
+ 2. Xpert 后端是否能访问 wx2.0。
298
+ 3. wx2.0 `/v1/message/sendtext` 是否可用。
299
+ 4. 是否需要配置 `API Token`。
300
+ 5. Workbench 出站日志里的错误信息。
301
+ 6. `失败时回退旧发送接口` 是否开启。
302
+
303
+ ### 一直重复触发或自问自答
304
+
305
+ 开启:
306
+
307
+ ```text
308
+ 忽略自己发出的消息
309
+ ```
310
+
311
+ 并确认 wx2.0 payload 中 `isself` 字段能正确标识自发消息。
312
+
313
+ ### 回调返回 400 或 Invalid callback secret
314
+
315
+ 说明插件配置了 `回调密钥`,但 wx2.0 推送时没有提供正确密钥。
316
+
317
+ 解决方式二选一:
318
+
319
+ ```text
320
+ <Xpert webhook URL>?secret=<callbackSecret>
321
+ ```
322
+
323
+ 或请求 header:
324
+
325
+ ```text
326
+ x-wechat-callback-secret: <callbackSecret>
327
+ ```
328
+
329
+ ## 本地开发
330
+
331
+ 在 `community` workspace 下执行:
332
+
333
+ ```sh
334
+ pnpm --filter @xpert-ai/plugin-community-wechat test
335
+ pnpm --filter @xpert-ai/plugin-community-wechat typecheck
336
+ pnpm --filter @xpert-ai/plugin-community-wechat build
337
+ ```
338
+
339
+ 插件主要入口:
340
+
341
+ - provider key:`wechat_personal`
342
+ - channel type:`wechat_personal`
343
+ - trigger key:`wechat_personal`
344
+ - view key:`wechat_personal_workbench`
345
+ - assistant template keys:`wechat-personal-admin-assistant`, `wechat-personal-user-assistant`
346
+ - middleware provider:`WechatPersonalRuntimeMiddleware`
347
+
348
+ ## 安全建议
349
+
350
+ - 生产环境建议配置 `callbackSecret`。
351
+ - 不要把 wx2.0 HTTP 服务直接暴露到公网,除非有额外鉴权和网络隔离。
352
+ - 如果 wx2.0 启用 TokenAuth,请填写 `API Token`。
353
+ - 不要在 Agent prompt 或用户可见消息里泄露 callback URL、token、integrationId 等内部配置。
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ import type { XpertPlugin } from '@xpert-ai/plugin-sdk';
3
+ declare const ConfigSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
4
+ declare const plugin: XpertPlugin<z.infer<typeof ConfigSchema>>;
5
+ export default plugin;
6
+ export * from './lib/constants.js';
7
+ export * from './lib/types.js';
8
+ export * from './lib/entities/index.js';
9
+ export * from './lib/handoff/index.js';
10
+ export * from './lib/workflow/index.js';
11
+ export * from './lib/conversation-user-key.js';
12
+ export * from './lib/conversation.service.js';
13
+ export * from './lib/wechat-personal-channel.strategy.js';
14
+ export * from './lib/wechat-personal.client.js';
15
+ export * from './lib/wechat-personal.controller.js';
16
+ export * from './lib/wechat-personal-integration.strategy.js';
17
+ export * from './lib/wechat-personal.middleware.js';
18
+ export * from './lib/wechat-personal.plugin.js';
19
+ export * from './lib/wechat-personal.templates.js';
20
+ export * from './lib/views/wechat-personal-view.provider.js';
package/dist/index.js ADDED
@@ -0,0 +1,139 @@
1
+ import { readFileSync } from 'fs';
2
+ import { dirname, join } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { z } from 'zod';
5
+ import { WECHAT_PERSONAL_FEATURE, WECHAT_PERSONAL_ICON, WECHAT_PERSONAL_MIDDLEWARE_NAME, WECHAT_PERSONAL_PLUGIN_NAME, WECHAT_PERSONAL_PROVIDER_KEY, WECHAT_PERSONAL_RUNTIME_FEATURE, WECHAT_PERSONAL_TEMPLATE_PROVIDER_KEY, WECHAT_PERSONAL_VIEW_KEY, WECHAT_PERSONAL_VIEW_PROVIDER_KEY } from './lib/constants.js';
6
+ import { WECHAT_PERSONAL_PLUGIN_CONTEXT } from './lib/tokens.js';
7
+ import { WechatPersonalPlugin } from './lib/wechat-personal.plugin.js';
8
+ import { wechatPersonalTemplates } from './lib/wechat-personal.templates.js';
9
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
10
+ const packageJson = JSON.parse(readFileSync(join(moduleDir, '../package.json'), 'utf8'));
11
+ const ConfigSchema = z.object({});
12
+ const plugin = {
13
+ meta: {
14
+ name: packageJson.name || WECHAT_PERSONAL_PLUGIN_NAME,
15
+ version: packageJson.version,
16
+ level: 'system',
17
+ targetApps: ['data-xpert'],
18
+ targetAppMeta: {
19
+ 'data-xpert': {
20
+ types: ['integration', 'workbench-view', 'assistant-tool', 'assistant-template'],
21
+ capabilities: [
22
+ WECHAT_PERSONAL_FEATURE,
23
+ WECHAT_PERSONAL_RUNTIME_FEATURE,
24
+ 'wechat-personal-workbench',
25
+ 'wechat-personal-admin-assistant-template',
26
+ 'wechat-personal-user-assistant-template'
27
+ ],
28
+ marketplace: {
29
+ contents: [
30
+ {
31
+ type: 'app',
32
+ name: WECHAT_PERSONAL_PROVIDER_KEY,
33
+ displayName: 'Personal WeChat',
34
+ description: 'Bridge wx2.0 personal WeChat messages with Xpert agents.',
35
+ icon: {
36
+ type: 'svg',
37
+ value: WECHAT_PERSONAL_ICON,
38
+ color: '#16a34a'
39
+ },
40
+ operations: [
41
+ {
42
+ name: 'receive-wechat-messages',
43
+ displayName: 'Receive personal WeChat messages',
44
+ description: 'Receive wx2.0 callbacks and dispatch normalized text messages to an Agent.',
45
+ access: 'read'
46
+ },
47
+ {
48
+ name: 'send-wechat-replies',
49
+ displayName: 'Send personal WeChat replies',
50
+ description: 'Send final Agent text replies through wx2.0 sendtext.',
51
+ access: 'write'
52
+ },
53
+ {
54
+ name: 'manage-wechat-runtime',
55
+ displayName: 'Manage WeChat runtime',
56
+ description: 'Review accounts, conversation bindings, message logs, callbacks, and configuration.',
57
+ access: 'write'
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ type: 'view',
63
+ name: WECHAT_PERSONAL_VIEW_KEY,
64
+ displayName: 'Personal WeChat Workbench',
65
+ description: 'Workbench for wx2.0 accounts, conversations, message logs, and callback setup.'
66
+ },
67
+ {
68
+ type: 'tool',
69
+ name: WECHAT_PERSONAL_MIDDLEWARE_NAME,
70
+ displayName: 'Personal WeChat Runtime Tools',
71
+ description: 'Assistant middleware for Personal WeChat runtime discovery, callback setup, account management, conversations, and logs.'
72
+ },
73
+ {
74
+ type: 'assistant-template',
75
+ name: 'wechat-personal-admin-assistant',
76
+ displayName: 'Personal WeChat Admin Assistant Template',
77
+ description: 'Organization-level assistant template for managing Personal WeChat integrations, callbacks, accounts, conversations, and logs.'
78
+ },
79
+ {
80
+ type: 'assistant-template',
81
+ name: 'wechat-personal-user-assistant',
82
+ displayName: 'Personal WeChat User Assistant Template',
83
+ description: 'End-user assistant template with a Personal WeChat trigger and final-text reply behavior.'
84
+ }
85
+ ]
86
+ },
87
+ runtime: {
88
+ integrationProviders: [WECHAT_PERSONAL_PROVIDER_KEY],
89
+ channelProviders: [WECHAT_PERSONAL_PROVIDER_KEY],
90
+ middlewareProviders: [WECHAT_PERSONAL_MIDDLEWARE_NAME],
91
+ viewProviders: [WECHAT_PERSONAL_VIEW_PROVIDER_KEY],
92
+ templateProviders: [WECHAT_PERSONAL_TEMPLATE_PROVIDER_KEY]
93
+ }
94
+ }
95
+ },
96
+ category: 'integration',
97
+ icon: {
98
+ type: 'svg',
99
+ value: WECHAT_PERSONAL_ICON,
100
+ color: '#16a34a'
101
+ },
102
+ displayName: 'Personal WeChat Plugin',
103
+ description: 'wx2.0 personal WeChat integration for webhook receiving, Agent dispatch, and sendtext replies.',
104
+ keywords: ['wechat', 'wx2.0', 'personal-wechat', 'integration', 'webhook', 'agent', 'remote-component'],
105
+ author: 'XpertAI Team'
106
+ },
107
+ config: {
108
+ schema: ConfigSchema
109
+ },
110
+ permissions: [
111
+ { type: 'integration', service: WECHAT_PERSONAL_PROVIDER_KEY, operations: ['read', 'write'] },
112
+ { type: 'handoff', operations: ['enqueue'] }
113
+ ],
114
+ templates: wechatPersonalTemplates,
115
+ register(ctx) {
116
+ return {
117
+ module: WechatPersonalPlugin,
118
+ global: true,
119
+ providers: [{ provide: WECHAT_PERSONAL_PLUGIN_CONTEXT, useValue: ctx }],
120
+ exports: []
121
+ };
122
+ }
123
+ };
124
+ export default plugin;
125
+ export * from './lib/constants.js';
126
+ export * from './lib/types.js';
127
+ export * from './lib/entities/index.js';
128
+ export * from './lib/handoff/index.js';
129
+ export * from './lib/workflow/index.js';
130
+ export * from './lib/conversation-user-key.js';
131
+ export * from './lib/conversation.service.js';
132
+ export * from './lib/wechat-personal-channel.strategy.js';
133
+ export * from './lib/wechat-personal.client.js';
134
+ export * from './lib/wechat-personal.controller.js';
135
+ export * from './lib/wechat-personal-integration.strategy.js';
136
+ export * from './lib/wechat-personal.middleware.js';
137
+ export * from './lib/wechat-personal.plugin.js';
138
+ export * from './lib/wechat-personal.templates.js';
139
+ export * from './lib/views/wechat-personal-view.provider.js';
@@ -0,0 +1,23 @@
1
+ export declare const WECHAT_PERSONAL_PLUGIN_NAME = "@xpert-ai/plugin-community-wechat";
2
+ export declare const WECHAT_PERSONAL_PROVIDER_KEY = "wechat_personal";
3
+ export declare const WECHAT_PERSONAL_CHANNEL_TYPE = "wechat_personal";
4
+ export declare const WECHAT_PERSONAL_TRIGGER_KEY = "wechat_personal";
5
+ export declare const WECHAT_PERSONAL_VIEW_PROVIDER_KEY = "wechat_personal_workbench_provider";
6
+ export declare const WECHAT_PERSONAL_VIEW_KEY = "wechat_personal_workbench";
7
+ export declare const WECHAT_PERSONAL_REMOTE_ENTRY_KEY = "wechat-personal-workbench";
8
+ export declare const WECHAT_PERSONAL_TEMPLATE_PROVIDER_KEY = "wechatPersonalTemplates";
9
+ export declare const WECHAT_PERSONAL_FEATURE = "wechat_personal_bridge";
10
+ export declare const WECHAT_PERSONAL_RUNTIME_FEATURE = "wechat-personal-runtime";
11
+ export declare const WECHAT_PERSONAL_WORKBENCH_FEATURE = "wechat-personal-workbench";
12
+ export declare const WECHAT_PERSONAL_MIDDLEWARE_NAME = "WechatPersonalRuntimeMiddleware";
13
+ export declare const WECHAT_PERSONAL_GET_RUNTIME_STATUS_TOOL_NAME = "wechat_personal_get_runtime_status";
14
+ export declare const WECHAT_PERSONAL_GET_CALLBACK_CONFIG_TOOL_NAME = "wechat_personal_get_callback_config";
15
+ export declare const WECHAT_PERSONAL_LIST_ACCOUNTS_TOOL_NAME = "wechat_personal_list_accounts";
16
+ export declare const WECHAT_PERSONAL_LIST_CONVERSATIONS_TOOL_NAME = "wechat_personal_list_conversations";
17
+ export declare const WECHAT_PERSONAL_SEARCH_MESSAGE_LOGS_TOOL_NAME = "wechat_personal_search_message_logs";
18
+ export declare const WECHAT_PERSONAL_RESET_CONVERSATION_TOOL_NAME = "wechat_personal_reset_conversation";
19
+ export declare const WECHAT_PERSONAL_REGISTER_CALLBACK_TOOL_NAME = "wechat_personal_register_callback";
20
+ export declare const WECHAT_PERSONAL_SET_ACCOUNT_ENABLED_TOOL_NAME = "wechat_personal_set_account_enabled";
21
+ export declare const AGENT_WORKBENCH_MAIN_SLOT = "agent.workbench.main";
22
+ export declare const AGENT_WORKBENCH_FIXED_SLOT = "agent.workbench.fixed";
23
+ export declare const WECHAT_PERSONAL_ICON = "<svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6.5 7.5C4.57 7.5 3 8.87 3 10.56c0 1 .55 1.89 1.41 2.45l-.37 1.43 1.6-.78c.28.05.57.08.86.08 1.93 0 3.5-1.37 3.5-3.06S8.43 7.5 6.5 7.5Z\" stroke=\"currentColor\" stroke-width=\"1.45\" stroke-linejoin=\"round\"/><path d=\"M13.4 5c4.2 0 7.6 2.82 7.6 6.3 0 1.94-1.06 3.68-2.72 4.83l.62 2.37-2.6-1.3c-.9.26-1.88.4-2.9.4-4.2 0-7.6-2.82-7.6-6.3S9.2 5 13.4 5Z\" stroke=\"currentColor\" stroke-width=\"1.45\" stroke-linejoin=\"round\"/><path d=\"M11 10.4h.01M15.8 10.4h.01\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\"/></svg>";
@@ -0,0 +1,23 @@
1
+ export const WECHAT_PERSONAL_PLUGIN_NAME = '@xpert-ai/plugin-community-wechat';
2
+ export const WECHAT_PERSONAL_PROVIDER_KEY = 'wechat_personal';
3
+ export const WECHAT_PERSONAL_CHANNEL_TYPE = 'wechat_personal';
4
+ export const WECHAT_PERSONAL_TRIGGER_KEY = 'wechat_personal';
5
+ export const WECHAT_PERSONAL_VIEW_PROVIDER_KEY = 'wechat_personal_workbench_provider';
6
+ export const WECHAT_PERSONAL_VIEW_KEY = 'wechat_personal_workbench';
7
+ export const WECHAT_PERSONAL_REMOTE_ENTRY_KEY = 'wechat-personal-workbench';
8
+ export const WECHAT_PERSONAL_TEMPLATE_PROVIDER_KEY = 'wechatPersonalTemplates';
9
+ export const WECHAT_PERSONAL_FEATURE = 'wechat_personal_bridge';
10
+ export const WECHAT_PERSONAL_RUNTIME_FEATURE = 'wechat-personal-runtime';
11
+ export const WECHAT_PERSONAL_WORKBENCH_FEATURE = 'wechat-personal-workbench';
12
+ export const WECHAT_PERSONAL_MIDDLEWARE_NAME = 'WechatPersonalRuntimeMiddleware';
13
+ export const WECHAT_PERSONAL_GET_RUNTIME_STATUS_TOOL_NAME = 'wechat_personal_get_runtime_status';
14
+ export const WECHAT_PERSONAL_GET_CALLBACK_CONFIG_TOOL_NAME = 'wechat_personal_get_callback_config';
15
+ export const WECHAT_PERSONAL_LIST_ACCOUNTS_TOOL_NAME = 'wechat_personal_list_accounts';
16
+ export const WECHAT_PERSONAL_LIST_CONVERSATIONS_TOOL_NAME = 'wechat_personal_list_conversations';
17
+ export const WECHAT_PERSONAL_SEARCH_MESSAGE_LOGS_TOOL_NAME = 'wechat_personal_search_message_logs';
18
+ export const WECHAT_PERSONAL_RESET_CONVERSATION_TOOL_NAME = 'wechat_personal_reset_conversation';
19
+ export const WECHAT_PERSONAL_REGISTER_CALLBACK_TOOL_NAME = 'wechat_personal_register_callback';
20
+ export const WECHAT_PERSONAL_SET_ACCOUNT_ENABLED_TOOL_NAME = 'wechat_personal_set_account_enabled';
21
+ export const AGENT_WORKBENCH_MAIN_SLOT = 'agent.workbench.main';
22
+ export const AGENT_WORKBENCH_FIXED_SLOT = 'agent.workbench.fixed';
23
+ export const WECHAT_PERSONAL_ICON = `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.5 7.5C4.57 7.5 3 8.87 3 10.56c0 1 .55 1.89 1.41 2.45l-.37 1.43 1.6-.78c.28.05.57.08.86.08 1.93 0 3.5-1.37 3.5-3.06S8.43 7.5 6.5 7.5Z" stroke="currentColor" stroke-width="1.45" stroke-linejoin="round"/><path d="M13.4 5c4.2 0 7.6 2.82 7.6 6.3 0 1.94-1.06 3.68-2.72 4.83l.62 2.37-2.6-1.3c-.9.26-1.88.4-2.9.4-4.2 0-7.6-2.82-7.6-6.3S9.2 5 13.4 5Z" stroke="currentColor" stroke-width="1.45" stroke-linejoin="round"/><path d="M11 10.4h.01M15.8 10.4h.01" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`;
@@ -0,0 +1,13 @@
1
+ export declare function normalizeConversationKey(value: unknown): string | undefined;
2
+ export declare function resolveWechatPersonalConversationUserKey(params: {
3
+ integrationId: string;
4
+ uuid: string;
5
+ contactId: string;
6
+ senderId?: string | null;
7
+ }): string | undefined;
8
+ export declare function parseWechatPersonalConversationUserKey(value: unknown): {
9
+ integrationId: string;
10
+ uuid: string;
11
+ contactId: string;
12
+ senderId: string;
13
+ } | undefined;
@@ -0,0 +1,28 @@
1
+ export function normalizeConversationKey(value) {
2
+ if (typeof value !== 'string') {
3
+ return undefined;
4
+ }
5
+ const text = value.trim();
6
+ return text || undefined;
7
+ }
8
+ export function resolveWechatPersonalConversationUserKey(params) {
9
+ const integrationId = normalizeConversationKey(params.integrationId);
10
+ const uuid = normalizeConversationKey(params.uuid);
11
+ const contactId = normalizeConversationKey(params.contactId);
12
+ const senderId = normalizeConversationKey(params.senderId) || contactId;
13
+ if (!integrationId || !uuid || !contactId || !senderId) {
14
+ return undefined;
15
+ }
16
+ return `${integrationId}:${uuid}:${contactId}:${senderId}`;
17
+ }
18
+ export function parseWechatPersonalConversationUserKey(value) {
19
+ const text = normalizeConversationKey(value);
20
+ if (!text) {
21
+ return undefined;
22
+ }
23
+ const [integrationId, uuid, contactId, senderId] = text.split(':');
24
+ if (!integrationId || !uuid || !contactId || !senderId) {
25
+ return undefined;
26
+ }
27
+ return { integrationId, uuid, contactId, senderId };
28
+ }