feat: 全新智能体功能
- 基于先进智能体框架,增加智能体编排功能 - 增加智能体聊天,并对接持久化
This commit is contained in:
@@ -6,6 +6,8 @@ public enum ChatType {
|
||||
TOOL_CALL,
|
||||
TOOL_RESULT,
|
||||
STATUS,
|
||||
CITATIONS,
|
||||
SESSION_CREATED,
|
||||
ERROR,
|
||||
FORM_REQUEST,
|
||||
FORM_CANCEL,
|
||||
|
||||
@@ -4,9 +4,10 @@ import com.alibaba.fastjson.JSON;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.web.context.request.async.AsyncRequestNotUsableException;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import tech.easyflow.common.util.StringUtil;
|
||||
import tech.easyflow.common.util.SpringContextUtil;
|
||||
import tech.easyflow.common.util.StringUtil;
|
||||
import tech.easyflow.core.chat.protocol.ChatEnvelope;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -90,15 +91,21 @@ public class ChatSseEmitter {
|
||||
.data(json)
|
||||
);
|
||||
return true;
|
||||
} catch (IllegalStateException e) {
|
||||
closed.compareAndSet(false, true);
|
||||
LOG.error("ChatSseEmitter send failed(event={}), message={}, exception={}", event, e.getMessage(), e.toString(), e);
|
||||
} catch (AsyncRequestNotUsableException e) {
|
||||
markDisconnected(event, e);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
LOG.error("ChatSseEmitter send io failed(event={}), message={}, exception={}", event, e.getMessage(), e.toString(), e);
|
||||
safeCompleteWithError(e);
|
||||
markDisconnected(event, e);
|
||||
return false;
|
||||
} catch (IllegalStateException e) {
|
||||
closed.compareAndSet(false, true);
|
||||
LOG.warn("ChatSseEmitter send failed(event={}), message={}, exception={}", event, e.getMessage(), e.toString());
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
if (isClientDisconnected(e)) {
|
||||
markDisconnected(event, e);
|
||||
return false;
|
||||
}
|
||||
LOG.error("ChatSseEmitter send unexpected failed(event={}), message={}, exception={}", event, e.getMessage(), e.toString(), e);
|
||||
safeCompleteWithError(e);
|
||||
return false;
|
||||
@@ -165,4 +172,31 @@ public class ChatSseEmitter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void markDisconnected(String event, Throwable ex) {
|
||||
closed.compareAndSet(false, true);
|
||||
LOG.warn("ChatSseEmitter client disconnected(event={}), message={}, exception={}",
|
||||
event, ex == null ? null : ex.getMessage(), ex == null ? null : ex.toString());
|
||||
}
|
||||
|
||||
private boolean isClientDisconnected(Throwable ex) {
|
||||
Throwable current = ex;
|
||||
while (current != null) {
|
||||
if (current instanceof AsyncRequestNotUsableException || current instanceof IOException) {
|
||||
return true;
|
||||
}
|
||||
String message = current.getMessage();
|
||||
if (message != null) {
|
||||
String lowerMessage = message.toLowerCase();
|
||||
if (lowerMessage.contains("broken pipe")
|
||||
|| lowerMessage.contains("connection reset")
|
||||
|| lowerMessage.contains("disconnected client")
|
||||
|| lowerMessage.contains("response not usable")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
current = current.getCause();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user