@eyeclaw/eyeclaw 2.0.11 → 2.0.13

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/client.ts +30 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eyeclaw/eyeclaw",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "EyeClaw channel plugin for OpenClaw - Connect your local OpenClaw instance to EyeClaw platform",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
package/src/client.ts CHANGED
@@ -39,24 +39,37 @@ export class EyeClawClient {
39
39
  }
40
40
 
41
41
  private handleOpen(): void {
42
- this.logger.info('WebSocket connected, subscribing to BotChannel...')
42
+ this.logger.info('WebSocket connected, subscribing to channels...')
43
43
  this.connected = true
44
44
 
45
- // Subscribe to BotChannel (token already passed in connection URL)
46
- const subscribeMessage = {
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
- this.send(subscribeMessage)
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 {
57
68
  try {
58
- const message = JSON.parse(data.toString())
59
- this.logger.debug(`Received message: ${JSON.stringify(message)}`)
69
+ const rawMessage = data.toString()
70
+ const message = JSON.parse(rawMessage)
71
+ this.logger.debug(`Raw message: ${rawMessage.substring(0, 200)}`)
72
+ this.logger.debug(`Parsed message type: ${message.type}, identifier: ${message.identifier}`)
60
73
 
61
74
  // ActionCable protocol messages
62
75
  if (message.type === 'ping') {
@@ -70,14 +83,20 @@ export class EyeClawClient {
70
83
  }
71
84
 
72
85
  if (message.type === 'confirm_subscription') {
73
- this.logger.info('✅ Successfully subscribed to BotChannel')
74
- this.startHeartbeat()
86
+ const identifier = message.identifier ? JSON.parse(message.identifier) : {}
87
+ this.logger.info(`✅ Subscribed to channel: ${identifier.channel || 'unknown'}`)
88
+ if (identifier.channel === 'BotChannel') {
89
+ this.startHeartbeat()
90
+ }
75
91
  return
76
92
  }
77
93
 
78
- // Channel messages
79
- if (message.message) {
80
- this.handleChannelMessage(message.message)
94
+ // Channel messages - handle both nested and direct formats
95
+ // BotChannel: message.message
96
+ // bot_X_commands: message.message or direct
97
+ const channelMessage = message.message || message
98
+ if (channelMessage && typeof channelMessage === 'object') {
99
+ this.handleChannelMessage(channelMessage)
81
100
  }
82
101
  } catch (error) {
83
102
  this.logger.error(`Failed to parse message: ${error}`)