rol-websocket-channel 1.8.1 → 1.8.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.
- package/dist/index.js +40 -35
- package/index.ts +40 -36
- 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.
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
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
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}
|
|
921
|
+
// after_tool_call:工具执行完毕(含结果或错误)时触发
|
|
922
|
+
api.on("after_tool_call", (event, ctx) => {
|
|
923
|
+
publishToolEvent({
|
|
924
|
+
type: "receiver",
|
|
925
|
+
source: "tools",
|
|
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
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
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
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1173
|
+
|
|
1174
|
+
// after_tool_call:工具执行完毕(含结果或错误)时触发
|
|
1175
|
+
api.on("after_tool_call", (event: any, ctx: any) => {
|
|
1176
|
+
publishToolEvent({
|
|
1177
|
+
type: "receiver",
|
|
1178
|
+
source: "tools",
|
|
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
|
}
|