refactor(gateway): print warn log while receiving invalid input

This commit is contained in:
2026-04-20 15:36:23 +08:00
parent e1a5a07e2a
commit ac715602a6
3 changed files with 14 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import work.slhaf.partner.framework.agent.interaction.AgentRuntime
import work.slhaf.partner.framework.agent.interaction.data.InteractionEvent.EventStatus
import work.slhaf.partner.framework.agent.interaction.data.Reply
import work.slhaf.partner.framework.agent.interaction.data.ReplyEvent
import work.slhaf.partner.framework.agent.model.StreamChatMessageConsumer
import kotlin.time.Duration.Companion.milliseconds
@@ -55,11 +55,11 @@ object ReplyDispatcher {
if (content.isEmpty()) {
return
}
val event = Reply(
val event = ReplyEvent(
status = EventStatus.RUNNING,
target = target,
content = content,
mode = Reply.ContentMode.APPEND,
mode = ReplyEvent.ContentMode.APPEND,
done = false
)
AgentRuntime.response(event)

View File

@@ -1,5 +1,6 @@
package work.slhaf.partner.runtime.gateway;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
@@ -121,9 +122,13 @@ public class WebSocketGateway extends WebSocketServer implements AgentGateway<In
@Override
public void onMessage(WebSocket webSocket, String s) {
InputData inputData = JSONObject.parseObject(s, InputData.class);
userSessions.put(inputData.getSource(), webSocket); // 注册连接
receive(inputData);
try {
InputData inputData = JSONObject.parseObject(s, InputData.class);
userSessions.put(inputData.getSource(), webSocket); // 注册连接
receive(inputData);
} catch (JSONException ignored) {
log.warn("Invalid input format: {}", s);
}
}
@Override