@eyeclaw/eyeclaw 2.3.3 → 2.3.5
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/package.json +1 -1
- package/src/types.ts +15 -0
- package/src/websocket-client.ts +30 -7
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -20,3 +20,18 @@ export interface BotStatus {
|
|
|
20
20
|
total_sessions: number
|
|
21
21
|
uptime: number
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
export interface WebSocketMessage {
|
|
25
|
+
type: string
|
|
26
|
+
command?: string
|
|
27
|
+
params?: {
|
|
28
|
+
message?: string
|
|
29
|
+
[key: string]: any
|
|
30
|
+
}
|
|
31
|
+
metadata?: {
|
|
32
|
+
session_id?: string
|
|
33
|
+
source?: string
|
|
34
|
+
[key: string]: any
|
|
35
|
+
}
|
|
36
|
+
[key: string]: any
|
|
37
|
+
}
|
package/src/websocket-client.ts
CHANGED
|
@@ -103,11 +103,17 @@ export class EyeClawWebSocketClient {
|
|
|
103
103
|
return
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
// Ping/pong
|
|
106
|
+
// Ping/pong (协议级别的 ping,直接响应 pong)
|
|
107
107
|
if (message.type === 'ping') {
|
|
108
108
|
this.send({ type: 'pong' })
|
|
109
109
|
return
|
|
110
110
|
}
|
|
111
|
+
|
|
112
|
+
// 处理 Rails BotChannel 的 pong 响应
|
|
113
|
+
if (message.type === 'pong') {
|
|
114
|
+
this.api.logger.debug('[EyeClaw] Received pong from server')
|
|
115
|
+
return
|
|
116
|
+
}
|
|
111
117
|
|
|
112
118
|
// Subscription confirmation
|
|
113
119
|
if (message.type === 'confirm_subscription') {
|
|
@@ -155,23 +161,28 @@ export class EyeClawWebSocketClient {
|
|
|
155
161
|
* 处理命令消息
|
|
156
162
|
*/
|
|
157
163
|
private async handleCommand(payload: WebSocketMessage) {
|
|
158
|
-
const { type,
|
|
164
|
+
const { type, params, metadata, command } = payload
|
|
159
165
|
|
|
160
166
|
// 只处理 execute_command 类型的消息
|
|
161
167
|
if (type !== 'execute_command' && type !== 'chat') {
|
|
162
168
|
return
|
|
163
169
|
}
|
|
164
|
-
|
|
165
|
-
|
|
170
|
+
|
|
171
|
+
// 从 params.message 或 command 提取用户消息
|
|
172
|
+
const userMessage = params?.message || command
|
|
166
173
|
if (!userMessage) {
|
|
167
174
|
this.api.logger.warn('[EyeClaw] No message content')
|
|
168
175
|
return
|
|
169
176
|
}
|
|
170
|
-
|
|
177
|
+
|
|
178
|
+
// 从 metadata 提取 session_id
|
|
179
|
+
const sessionId = metadata?.session_id
|
|
180
|
+
|
|
171
181
|
this.api.logger.info(`[EyeClaw] Processing: ${userMessage.substring(0, 50)}...`)
|
|
182
|
+
this.api.logger.info(`[EyeClaw] Session ID: ${sessionId}`)
|
|
172
183
|
|
|
173
184
|
// 通过 OpenClaw API 处理消息,获取流式响应
|
|
174
|
-
await this.processWithOpenClaw(userMessage,
|
|
185
|
+
await this.processWithOpenClaw(userMessage, sessionId)
|
|
175
186
|
}
|
|
176
187
|
|
|
177
188
|
/**
|
|
@@ -320,7 +331,19 @@ export class EyeClawWebSocketClient {
|
|
|
320
331
|
*/
|
|
321
332
|
private startPing() {
|
|
322
333
|
this.pingInterval = setInterval(() => {
|
|
323
|
-
|
|
334
|
+
// 调用 Rails BotChannel 的 ping action
|
|
335
|
+
const channelIdentifier = JSON.stringify({
|
|
336
|
+
channel: 'BotChannel',
|
|
337
|
+
bot_id: this.config.botId,
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
this.send({
|
|
341
|
+
command: 'message',
|
|
342
|
+
identifier: channelIdentifier,
|
|
343
|
+
data: JSON.stringify({
|
|
344
|
+
action: 'ping',
|
|
345
|
+
}),
|
|
346
|
+
})
|
|
324
347
|
}, 60000) // 60秒心跳一次
|
|
325
348
|
}
|
|
326
349
|
|