rol-websocket-channel 1.7.8 → 1.7.9

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/dist/index.js CHANGED
@@ -291,7 +291,7 @@ const WebSocketChannel = {
291
291
  if (targetTopic.endsWith("#")) {
292
292
  targetTopic = targetTopic.slice(0, -1) + "bot";
293
293
  }
294
- conn.ws.publish(targetTopic, message);
294
+ conn.ws.publish(targetTopic, message, { retain: true });
295
295
  return { ok: true };
296
296
  },
297
297
  sendMedia: async ({ to, text, mediaUrl }) => {
@@ -309,7 +309,7 @@ const WebSocketChannel = {
309
309
  if (targetTopic.endsWith("#")) {
310
310
  targetTopic = targetTopic.slice(0, -1) + "bot";
311
311
  }
312
- conn.ws.publish(targetTopic, message);
312
+ conn.ws.publish(targetTopic, message, { retain: true });
313
313
  return { ok: true };
314
314
  },
315
315
  },
@@ -362,7 +362,7 @@ const WebSocketChannel = {
362
362
  if (targetTopic.endsWith("#")) {
363
363
  targetTopic = targetTopic.slice(0, -1) + "bot";
364
364
  }
365
- conn.ws.publish(targetTopic, replyMessage);
365
+ conn.ws.publish(targetTopic, replyMessage, { retain: true });
366
366
  return {
367
367
  content: [{ type: "text", text: JSON.stringify({ ok: true }) }],
368
368
  details: {},
@@ -583,7 +583,7 @@ async function handleIncomingMessage(payload, account, cfg, runtime, log, mqttTo
583
583
  targetTopic = targetTopic.slice(0, -1) + 'app';
584
584
  }
585
585
  targetTopic = targetTopic.replace('device', 'app').replace('bot', 'app');
586
- conn.ws.publish(targetTopic, JSON.stringify(replyMessage));
586
+ conn.ws.publish(targetTopic, JSON.stringify(replyMessage), { retain: true });
587
587
  },
588
588
  onError: (err) => {
589
589
  log?.error(`[rol-websocket-channel] Delivery error: ${err.message} ${err.stack}`);
@@ -727,7 +727,7 @@ function publishCustomMessageResponse(response, innerData, mqttTopic) {
727
727
  targetTopic = targetTopic.slice(0, -1) + 'app';
728
728
  }
729
729
  targetTopic = targetTopic.replace('device', 'app').replace('bot', 'app');
730
- conn.ws.publish(targetTopic, JSON.stringify(response));
730
+ conn.ws.publish(targetTopic, JSON.stringify(response), { retain: true });
731
731
  }
732
732
  }
733
733
  // ============================================
@@ -159,13 +159,13 @@ async function readSessionMessages(filePath, limit, beforeId) {
159
159
  throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `beforeId not found: ${beforeId}`);
160
160
  }
161
161
  const start = Math.max(0, endExclusive - limit);
162
- const items = messages.slice(start, endExclusive);
162
+ const items = messages.slice(start, endExclusive).reverse();
163
163
  const hasMore = start > 0;
164
- const firstItemId = typeof items[0]?.id === 'string' ? items[0].id : null;
164
+ const lastItemId = typeof items[items.length - 1]?.id === 'string' ? items[items.length - 1].id : null;
165
165
  return {
166
166
  total: messages.length,
167
167
  hasMore,
168
- nextBeforeId: hasMore ? firstItemId : null,
168
+ nextBeforeId: hasMore ? lastItemId : null,
169
169
  items
170
170
  };
171
171
  }
@@ -183,12 +183,12 @@ export function closeGlobalConnection() {
183
183
  * 向指定 topic 发布消息(使用全局连接)
184
184
  * @returns 发布成功返回 true,未连接返回 false
185
185
  */
186
- export function publishGlobalMessage(topic, message) {
186
+ export function publishGlobalMessage(topic, message, options) {
187
187
  if (!isGlobalConnected()) {
188
188
  console.error("[MQTT] ❌ publishGlobalMessage: no connected global connection");
189
189
  return false;
190
190
  }
191
- globalConnection.ws.publish(topic, message);
191
+ globalConnection.ws.publish(topic, message, options);
192
192
  console.log(`[MQTT] publishGlobalMessage: published to ${topic}`);
193
193
  return true;
194
194
  }
@@ -83,9 +83,9 @@ export class GlobalMqttClient {
83
83
  * 向指定 topic 发布消息
84
84
  * @returns 发布成功返回 true,未连接返回 false
85
85
  */
86
- publish(topic, message) {
86
+ publish(topic, message, options) {
87
87
  console.log(`[MQTT] GlobalMqttClient.publish(): topic=${topic}`);
88
- return ConnectionManager.publishGlobalMessage(topic, message);
88
+ return ConnectionManager.publishGlobalMessage(topic, message, options);
89
89
  }
90
90
  /**
91
91
  * 检查全局连接是否处于已连接状态
package/index.ts CHANGED
@@ -357,7 +357,7 @@ const WebSocketChannel: any = {
357
357
  targetTopic = targetTopic.slice(0, -1) + "bot";
358
358
  }
359
359
 
360
- conn.ws.publish(targetTopic, message);
360
+ conn.ws.publish(targetTopic, message, { retain: true });
361
361
  return { ok: true };
362
362
  },
363
363
 
@@ -379,7 +379,7 @@ const WebSocketChannel: any = {
379
379
  targetTopic = targetTopic.slice(0, -1) + "bot";
380
380
  }
381
381
 
382
- conn.ws.publish(targetTopic, message);
382
+ conn.ws.publish(targetTopic, message, { retain: true });
383
383
  return { ok: true };
384
384
  },
385
385
  },
@@ -439,7 +439,7 @@ const WebSocketChannel: any = {
439
439
  targetTopic = targetTopic.slice(0, -1) + "bot";
440
440
  }
441
441
 
442
- conn.ws.publish(targetTopic, replyMessage);
442
+ conn.ws.publish(targetTopic, replyMessage, { retain: true });
443
443
 
444
444
  return {
445
445
  content: [{ type: "text" as const, text: JSON.stringify({ ok: true }) }],
@@ -736,7 +736,7 @@ async function handleIncomingMessage(
736
736
  }
737
737
  targetTopic = targetTopic.replace('device', 'app').replace('bot', 'app');
738
738
 
739
- conn.ws.publish(targetTopic, JSON.stringify(replyMessage));
739
+ conn.ws.publish(targetTopic, JSON.stringify(replyMessage), { retain: true });
740
740
  },
741
741
  onError: (err: Error) => {
742
742
  log?.error(`[rol-websocket-channel] Delivery error: ${err.message} ${err.stack}`);
@@ -914,7 +914,7 @@ function publishCustomMessageResponse(response: any, innerData: any, mqttTopic:
914
914
  }
915
915
  targetTopic = targetTopic.replace('device', 'app').replace('bot', 'app');
916
916
 
917
- conn.ws.publish(targetTopic, JSON.stringify(response));
917
+ conn.ws.publish(targetTopic, JSON.stringify(response), { retain: true });
918
918
  }
919
919
  }
920
920
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rol-websocket-channel",
3
- "version": "1.7.8",
3
+ "version": "1.7.9",
4
4
  "description": "Unified OpenClaw plugin: MQTT Channel + Admin Bridge for remote management",
5
5
  "license": "MIT",
6
6
  "author": "nixgnehc",
@@ -242,14 +242,14 @@ async function readSessionMessages(
242
242
  }
243
243
 
244
244
  const start = Math.max(0, endExclusive - limit);
245
- const items = messages.slice(start, endExclusive);
245
+ const items = messages.slice(start, endExclusive).reverse();
246
246
  const hasMore = start > 0;
247
- const firstItemId = typeof items[0]?.id === 'string' ? items[0].id : null;
247
+ const lastItemId = typeof items[items.length - 1]?.id === 'string' ? items[items.length - 1].id : null;
248
248
 
249
249
  return {
250
250
  total: messages.length,
251
251
  hasMore,
252
- nextBeforeId: hasMore ? firstItemId : null,
252
+ nextBeforeId: hasMore ? lastItemId : null,
253
253
  items
254
254
  };
255
255
  }
@@ -224,14 +224,14 @@ export function closeGlobalConnection(): void {
224
224
  * 向指定 topic 发布消息(使用全局连接)
225
225
  * @returns 发布成功返回 true,未连接返回 false
226
226
  */
227
- export function publishGlobalMessage(topic: string, message: string): boolean {
227
+ export function publishGlobalMessage(topic: string, message: string, options?: any): boolean {
228
228
  if (!isGlobalConnected()) {
229
229
  console.error(
230
230
  "[MQTT] ❌ publishGlobalMessage: no connected global connection",
231
231
  );
232
232
  return false;
233
233
  }
234
- globalConnection!.ws.publish(topic, message);
234
+ globalConnection!.ws.publish(topic, message, options);
235
235
  console.log(`[MQTT] publishGlobalMessage: published to ${topic}`);
236
236
  return true;
237
237
  }
@@ -140,9 +140,9 @@ export class GlobalMqttClient {
140
140
  * 向指定 topic 发布消息
141
141
  * @returns 发布成功返回 true,未连接返回 false
142
142
  */
143
- publish(topic: string, message: string): boolean {
143
+ publish(topic: string, message: string, options?: any): boolean {
144
144
  console.log(`[MQTT] GlobalMqttClient.publish(): topic=${topic}`);
145
- return ConnectionManager.publishGlobalMessage(topic, message);
145
+ return ConnectionManager.publishGlobalMessage(topic, message, options);
146
146
  }
147
147
 
148
148
  /**