@eyeclaw/eyeclaw 2.0.10 → 2.0.12
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/client.ts +29 -9
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -39,18 +39,29 @@ export class EyeClawClient {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
private handleOpen(): void {
|
|
42
|
-
this.logger.info('WebSocket connected, subscribing to
|
|
42
|
+
this.logger.info('WebSocket connected, subscribing to channels...')
|
|
43
43
|
this.connected = true
|
|
44
44
|
|
|
45
|
-
// Subscribe to BotChannel (
|
|
46
|
-
const
|
|
45
|
+
// Subscribe to BotChannel (for responses back to EyeClaw platform)
|
|
46
|
+
const subscribeBotChannel = {
|
|
47
47
|
command: 'subscribe',
|
|
48
48
|
identifier: JSON.stringify({
|
|
49
49
|
channel: 'BotChannel',
|
|
50
50
|
}),
|
|
51
51
|
}
|
|
52
|
+
this.send(subscribeBotChannel)
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
// Subscribe to bot_{id}_commands channel (for commands from Rails)
|
|
55
|
+
// This is where /sse/rokid broadcasts commands
|
|
56
|
+
const botId = this.config.botId
|
|
57
|
+
const subscribeCommands = {
|
|
58
|
+
command: 'subscribe',
|
|
59
|
+
identifier: JSON.stringify({
|
|
60
|
+
channel: `bot_${botId}_commands`,
|
|
61
|
+
}),
|
|
62
|
+
}
|
|
63
|
+
this.logger.info(`Subscribing to bot_${botId}_commands channel...`)
|
|
64
|
+
this.send(subscribeCommands)
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
private handleMessage(data: WebSocket.Data): void {
|
|
@@ -70,14 +81,20 @@ export class EyeClawClient {
|
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
if (message.type === 'confirm_subscription') {
|
|
73
|
-
|
|
74
|
-
this.
|
|
84
|
+
const identifier = message.identifier ? JSON.parse(message.identifier) : {}
|
|
85
|
+
this.logger.info(`✅ Subscribed to channel: ${identifier.channel || 'unknown'}`)
|
|
86
|
+
if (identifier.channel === 'BotChannel') {
|
|
87
|
+
this.startHeartbeat()
|
|
88
|
+
}
|
|
75
89
|
return
|
|
76
90
|
}
|
|
77
91
|
|
|
78
|
-
// Channel messages
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
// Channel messages - handle both nested and direct formats
|
|
93
|
+
// BotChannel: message.message
|
|
94
|
+
// bot_X_commands: message.message or direct
|
|
95
|
+
const channelMessage = message.message || message
|
|
96
|
+
if (channelMessage && typeof channelMessage === 'object') {
|
|
97
|
+
this.handleChannelMessage(channelMessage)
|
|
81
98
|
}
|
|
82
99
|
} catch (error) {
|
|
83
100
|
this.logger.error(`Failed to parse message: ${error}`)
|
|
@@ -87,6 +104,9 @@ export class EyeClawClient {
|
|
|
87
104
|
private handleChannelMessage(message: Record<string, unknown>): void {
|
|
88
105
|
const { type } = message
|
|
89
106
|
|
|
107
|
+
// Debug: log all message types
|
|
108
|
+
this.logger.debug(`📩 Channel message: ${JSON.stringify(message)}`)
|
|
109
|
+
|
|
90
110
|
switch (type) {
|
|
91
111
|
case 'connected':
|
|
92
112
|
this.sessionId = message.session_id as string
|