rol-websocket-channel 1.8.0 → 1.8.2

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 (3) hide show
  1. package/dist/index.js +40 -35
  2. package/index.ts +40 -36
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -895,45 +895,50 @@ function publishToolEvent(event) {
895
895
  try {
896
896
  conn.ws.publish(targetTopic, JSON.stringify(event));
897
897
  }
898
- catch {
899
- // 忽略发布错误,避免影响主流程
898
+ catch (err) {
899
+ console.error("[mqtt] Error publishing tool event:", err);
900
900
  }
901
901
  }
902
902
  function registerToolEventHooks(api) {
903
903
  // before_tool_call:AI 即将调用某个工具时触发
904
- api.registerHook("before_tool_call", (event, ctx) => {
905
- publishToolEvent({
906
- type: "receiver",
907
- source: "tools",
908
- event: "before_tool_call",
909
- timestamp: Date.now(),
910
- data: {
911
- toolName: event.toolName,
912
- toolCallId: event.toolCallId,
913
- runId: event.runId ?? ctx.runId,
914
- sessionKey: ctx.sessionKey,
915
- agentId: ctx.agentId,
916
- params: event.params,
917
- },
904
+ if (typeof api.on === 'function') {
905
+ api.on("before_tool_call", (event, ctx) => {
906
+ publishToolEvent({
907
+ type: "receiver",
908
+ source: "tools",
909
+ event: "before_tool_call",
910
+ timestamp: Date.now(),
911
+ data: {
912
+ toolName: event.toolName,
913
+ toolCallId: event.toolCallId,
914
+ runId: event.runId ?? ctx.runId,
915
+ sessionKey: ctx.sessionKey,
916
+ agentId: ctx.agentId,
917
+ params: event.params,
918
+ },
919
+ });
918
920
  });
919
- });
920
- // after_tool_call:工具执行完毕(含结果或错误)时触发
921
- api.registerHook("after_tool_call", (event, ctx) => {
922
- publishToolEvent({
923
- type: "tool_event",
924
- source: "system",
925
- event: "after_tool_call",
926
- timestamp: Date.now(),
927
- data: {
928
- toolName: event.toolName,
929
- toolCallId: event.toolCallId,
930
- runId: event.runId ?? ctx.runId,
931
- sessionKey: ctx.sessionKey,
932
- agentId: ctx.agentId,
933
- durationMs: event.durationMs,
934
- error: event.error,
935
- result: event.result,
936
- },
921
+ // after_tool_call:工具执行完毕(含结果或错误)时触发
922
+ api.on("after_tool_call", (event, ctx) => {
923
+ publishToolEvent({
924
+ type: "tool_event",
925
+ source: "system",
926
+ event: "after_tool_call",
927
+ timestamp: Date.now(),
928
+ data: {
929
+ toolName: event.toolName,
930
+ toolCallId: event.toolCallId,
931
+ runId: event.runId ?? ctx.runId,
932
+ sessionKey: ctx.sessionKey,
933
+ agentId: ctx.agentId,
934
+ durationMs: event.durationMs,
935
+ error: event.error,
936
+ result: event.result,
937
+ },
938
+ });
937
939
  });
938
- });
940
+ }
941
+ else {
942
+ console.error("[mqtt] api.on is not available. Cannot register tool event hooks.");
943
+ }
939
944
  }
package/index.ts CHANGED
@@ -1146,47 +1146,51 @@ function publishToolEvent(event: object): void {
1146
1146
 
1147
1147
  try {
1148
1148
  conn.ws.publish(targetTopic, JSON.stringify(event));
1149
- } catch {
1150
- // 忽略发布错误,避免影响主流程
1149
+ } catch (err) {
1150
+ console.error("[mqtt] Error publishing tool event:", err);
1151
1151
  }
1152
1152
  }
1153
1153
 
1154
1154
  function registerToolEventHooks(api: any): void {
1155
1155
  // before_tool_call:AI 即将调用某个工具时触发
1156
- api.registerHook("before_tool_call", (event: any, ctx: any) => {
1157
- publishToolEvent({
1158
- type: "receiver",
1159
- source: "tools",
1160
- event: "before_tool_call",
1161
- timestamp: Date.now(),
1162
- data: {
1163
- toolName: event.toolName,
1164
- toolCallId: event.toolCallId,
1165
- runId: event.runId ?? ctx.runId,
1166
- sessionKey: ctx.sessionKey,
1167
- agentId: ctx.agentId,
1168
- params: event.params,
1169
- },
1156
+ if (typeof api.on === 'function') {
1157
+ api.on("before_tool_call", (event: any, ctx: any) => {
1158
+ publishToolEvent({
1159
+ type: "receiver",
1160
+ source: "tools",
1161
+ event: "before_tool_call",
1162
+ timestamp: Date.now(),
1163
+ data: {
1164
+ toolName: event.toolName,
1165
+ toolCallId: event.toolCallId,
1166
+ runId: event.runId ?? ctx.runId,
1167
+ sessionKey: ctx.sessionKey,
1168
+ agentId: ctx.agentId,
1169
+ params: event.params,
1170
+ },
1171
+ });
1170
1172
  });
1171
- });
1172
-
1173
- // after_tool_call:工具执行完毕(含结果或错误)时触发
1174
- api.registerHook("after_tool_call", (event: any, ctx: any) => {
1175
- publishToolEvent({
1176
- type: "tool_event",
1177
- source: "system",
1178
- event: "after_tool_call",
1179
- timestamp: Date.now(),
1180
- data: {
1181
- toolName: event.toolName,
1182
- toolCallId: event.toolCallId,
1183
- runId: event.runId ?? ctx.runId,
1184
- sessionKey: ctx.sessionKey,
1185
- agentId: ctx.agentId,
1186
- durationMs: event.durationMs,
1187
- error: event.error,
1188
- result: event.result,
1189
- },
1173
+
1174
+ // after_tool_call:工具执行完毕(含结果或错误)时触发
1175
+ api.on("after_tool_call", (event: any, ctx: any) => {
1176
+ publishToolEvent({
1177
+ type: "tool_event",
1178
+ source: "system",
1179
+ event: "after_tool_call",
1180
+ timestamp: Date.now(),
1181
+ data: {
1182
+ toolName: event.toolName,
1183
+ toolCallId: event.toolCallId,
1184
+ runId: event.runId ?? ctx.runId,
1185
+ sessionKey: ctx.sessionKey,
1186
+ agentId: ctx.agentId,
1187
+ durationMs: event.durationMs,
1188
+ error: event.error,
1189
+ result: event.result,
1190
+ },
1191
+ });
1190
1192
  });
1191
- });
1193
+ } else {
1194
+ console.error("[mqtt] api.on is not available. Cannot register tool event hooks.");
1195
+ }
1192
1196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rol-websocket-channel",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "Unified OpenClaw plugin: MQTT Channel + Admin Bridge for remote management",
5
5
  "license": "MIT",
6
6
  "author": "nixgnehc",