xiaozuoassistant 0.2.17 → 0.2.18

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.
@@ -8,65 +8,78 @@ export class FeishuChannel extends BaseChannel {
8
8
  this.bots = [];
9
9
  }
10
10
  async start() {
11
- // 每次 start 时重新读取最新配置,避免使用旧缓存
12
- const feishuConfig = config.channels?.feishu;
13
- // 清空现有机器人
14
- this.bots = [];
15
- // 检查配置是否为数组
16
- if (!Array.isArray(feishuConfig) || feishuConfig.length === 0) {
17
- console.log('Feishu bots not configured, skipping Feishu channel.');
18
- return;
19
- }
20
- // 为每个机器人初始化客户端
21
- for (const botConfig of feishuConfig) {
22
- const { name, appId, appSecret } = botConfig;
23
- if (!name || !appId || !appSecret) {
24
- console.warn(`Feishu bot ${name || 'unknown'} missing required config, skipping.`);
25
- continue;
11
+ try {
12
+ // 每次 start 时重新读取最新配置,避免使用旧缓存
13
+ const feishuConfig = config.channels?.feishu;
14
+ // 清空现有机器人
15
+ this.bots = [];
16
+ // 检查配置是否为数组
17
+ if (!Array.isArray(feishuConfig) || feishuConfig.length === 0) {
18
+ console.log('Feishu bots not configured, skipping Feishu channel.');
19
+ return;
26
20
  }
27
- try {
28
- // Initialize Lark Client for API calls
29
- const client = new lark.Client({
30
- appId,
31
- appSecret,
32
- appType: lark.AppType.SelfBuild,
33
- domain: lark.Domain.Feishu,
34
- });
35
- // Initialize WebSocket Client for receiving events
36
- const wsClient = new lark.WSClient({
37
- appId,
38
- appSecret,
39
- });
40
- // Start WebSocket client
41
- await wsClient.start({
42
- eventDispatcher: new lark.EventDispatcher({}).register({
43
- 'im.message.receive_v1': async (data) => {
44
- const event = data.message;
45
- if (!event || !data.sender)
46
- return;
47
- // Ignore bot messages
48
- if (data.sender.sender_type !== 'user')
49
- return;
50
- try {
51
- const content = JSON.parse(event.content).text;
52
- // Use chat_id for group chats, open_id/user_id for p2p?
53
- // Actually message.chat_id is universal for where the message comes from.
54
- const sessionId = `feishu:${name}:${event.chat_id}`;
55
- this.emitMessage(sessionId, content);
21
+ console.log(`Found ${feishuConfig.length} Feishu bot(s) in config`);
22
+ // 为每个机器人初始化客户端
23
+ for (const botConfig of feishuConfig) {
24
+ const { name, appId, appSecret } = botConfig;
25
+ if (!name || !appId || !appSecret) {
26
+ console.warn(`Feishu bot ${name || 'unknown'} missing required config, skipping.`);
27
+ continue;
28
+ }
29
+ try {
30
+ console.log(`Initializing Feishu Bot: ${name}`);
31
+ // Initialize Lark Client for API calls
32
+ const client = new lark.Client({
33
+ appId,
34
+ appSecret,
35
+ appType: lark.AppType.SelfBuild,
36
+ domain: lark.Domain.Feishu,
37
+ });
38
+ // Initialize WebSocket Client for receiving events
39
+ const wsClient = new lark.WSClient({
40
+ appId,
41
+ appSecret,
42
+ });
43
+ // Start WebSocket client
44
+ console.log(`Starting WebSocket client for Feishu Bot: ${name}`);
45
+ await wsClient.start({
46
+ eventDispatcher: new lark.EventDispatcher({}).register({
47
+ 'im.message.receive_v1': async (data) => {
48
+ console.log(`[Feishu-${name}] Received message event:`, data);
49
+ const event = data.message;
50
+ if (!event || !data.sender)
51
+ return;
52
+ // Ignore bot messages
53
+ if (data.sender.sender_type !== 'user') {
54
+ console.log(`[Feishu-${name}] Ignoring bot message`);
55
+ return;
56
+ }
57
+ try {
58
+ const content = JSON.parse(event.content).text;
59
+ console.log(`[Feishu-${name}] Received message: ${content}`);
60
+ // Use chat_id for group chats, open_id/user_id for p2p?
61
+ // Actually message.chat_id is universal for where the message comes from.
62
+ const sessionId = `feishu:${name}:${event.chat_id}`;
63
+ console.log(`[Feishu-${name}] Emitting message with sessionId: ${sessionId}`);
64
+ this.emitMessage(sessionId, content);
65
+ }
66
+ catch (e) {
67
+ console.error(`[Feishu-${name}] Failed to parse message content:`, e);
68
+ }
56
69
  }
57
- catch (e) {
58
- console.error(`[Feishu-${name}] Failed to parse message content:`, e);
59
- }
60
- }
61
- })
62
- });
63
- this.bots.push({ name, client, wsClient });
64
- console.log(`Feishu Bot ${name} Started (WebSocket Mode)`);
65
- }
66
- catch (error) {
67
- console.error(`[Feishu-${name}] Failed to start WebSocket client:`, error);
70
+ })
71
+ });
72
+ this.bots.push({ name, client, wsClient });
73
+ console.log(`Feishu Bot ${name} Started (WebSocket Mode)`);
74
+ }
75
+ catch (error) {
76
+ console.error(`[Feishu-${name}] Failed to start WebSocket client:`, error);
77
+ }
68
78
  }
69
79
  }
80
+ catch (error) {
81
+ console.error('Feishu channel start failed:', error);
82
+ }
70
83
  }
71
84
  async stop() {
72
85
  // There is no explicit stop method for WSClient in the current SDK version exposed clearly,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "A local-first personal AI assistant with multi-channel support and enhanced memory.",
5
5
  "author": "mantle.lau",
6
6
  "license": "MIT",