rol-websocket-channel 1.1.2 → 1.1.3

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.
@@ -1,4 +1,4 @@
1
- # OpenClaw MQTT API 文档 (配对逻辑更新)
1
+ # OpenClaw MQTT API 文档 (新增文件功能)
2
2
 
3
3
  ## 消息格式
4
4
 
@@ -1671,7 +1671,7 @@ openclaw admin-bridge pair <key> --endpoint https://api.deotaland.ai
1671
1671
 
1672
1672
  MQTT 请求示例:
1673
1673
 
1674
- ```json
1674
+ ​```json
1675
1675
  {
1676
1676
  "type": "artifactsList",
1677
1677
  "trace_id": "artifact-list-before-download-001",
package/index.ts CHANGED
@@ -507,7 +507,15 @@ async function handleIncomingMessage(
507
507
  timestamp: Date.now(),
508
508
  };
509
509
 
510
- conn.ws.publish(mqttTopic, JSON.stringify(replyMessage));
510
+ // 根据 source_type 修改 topic 末尾的 #
511
+ let targetTopic = mqttTopic;
512
+ const sourceType = innerData?.source_type;
513
+ if (targetTopic.endsWith("#")) {
514
+ const replacement = sourceType === "device" ? "device" : "bot";
515
+ targetTopic = targetTopic.slice(0, -1) + replacement;
516
+ }
517
+
518
+ conn.ws.publish(targetTopic, JSON.stringify(replyMessage));
511
519
  },
512
520
  onError: (err: Error) => {
513
521
  log?.error(`[rol-websocket-channel] Delivery error: ${err.message}`);
@@ -570,7 +578,15 @@ async function handleCustomMessageType(
570
578
 
571
579
  const conn = ConnectionManager.getGlobalConnection();
572
580
  if (conn && conn.ws && conn.ws.connected) {
573
- conn.ws.publish(mqttTopic, JSON.stringify(response));
581
+ // 根据 source_type 修改 topic 末尾的 #
582
+ let targetTopic = mqttTopic;
583
+ const sourceType = innerData?.source_type;
584
+ if (targetTopic.endsWith("#")) {
585
+ const replacement = sourceType === "device" ? "device" : "bot";
586
+ targetTopic = targetTopic.slice(0, -1) + replacement;
587
+ }
588
+
589
+ conn.ws.publish(targetTopic, JSON.stringify(response));
574
590
  }
575
591
  }
576
592
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rol-websocket-channel",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Unified OpenClaw plugin: MQTT Channel + Admin Bridge for remote management",
5
5
  "license": "MIT",
6
6
  "author": "nixgnehc",
@@ -136,9 +136,9 @@ export const logs: MethodHandler = async (params: any, context: MethodContext):
136
136
  return { ok: false, error: `No .log files found in directory: ${logDir}` };
137
137
  }
138
138
 
139
- const limit = params?.limit ?? 200;
139
+ const limit = 10;
140
140
  const maxBytes = params?.maxBytes ?? 250000;
141
- let offset = params?.offset;
141
+ const offset = undefined;
142
142
 
143
143
  // 获取所有候选日志的详细信息并排序(对应 ls -t)
144
144
  const fileStats = await Promise.all(
@@ -180,7 +180,9 @@ export const logs: MethodHandler = async (params: any, context: MethodContext):
180
180
  const content = buffer.toString('utf-8');
181
181
  const rawLines = content.split(/\r?\n/).filter(line => line.trim().length > 0);
182
182
 
183
- const resultLines = typeof offset === 'number' ? rawLines : rawLines.slice(-limit);
183
+ const resultLines = typeof offset === 'number'
184
+ ? rawLines
185
+ : rawLines.slice(-limit).reverse();
184
186
 
185
187
  return {
186
188
  ok: true,