feat: 接入聊天历史界面与外链会话恢复

- 新增管理端与用户端聊天历史接口和页面

- 外链聊天支持访问令牌登录、身份保活与当前会话恢复

- 聊天执行链路切到统一 runtime 与 chatlog 查询接口
This commit is contained in:
2026-04-05 11:37:25 +08:00
parent 25e80433a5
commit a4f75a5e4c
48 changed files with 3724 additions and 972 deletions

View File

@@ -13,10 +13,13 @@ import tech.easyflow.ai.service.BotService;
import tech.easyflow.ai.service.impl.BotServiceImpl;
import tech.easyflow.common.domain.Result;
import tech.easyflow.core.chat.protocol.sse.ChatSseUtil;
import tech.easyflow.core.runtime.ChatChannel;
import tech.easyflow.core.runtime.ChatRuntimeContext;
import tech.easyflow.system.entity.SysApiKey;
import tech.easyflow.system.service.SysApiKeyService;
import javax.annotation.Resource;
import java.math.BigInteger;
/**
* bot 接口
@@ -51,6 +54,7 @@ public class PublicBotController {
return ChatSseUtil.sendSystemError(null, "Apikey不能为空!");
}
sysApiKeyService.checkApikeyPermission(apikey, requestURI);
SysApiKey sysApiKey = sysApiKeyService.getSysApiKey(apikey);
BotServiceImpl.ChatCheckResult chatCheckResult = new BotServiceImpl.ChatCheckResult();
int size = chatRequestParams.getMessages().size();
String prompt = null;
@@ -62,7 +66,30 @@ public class PublicBotController {
if (errorEmitter != null) {
return errorEmitter;
}
return botService.startPublicChat(chatRequestParams.getBotId(), prompt, chatRequestParams.getMessages(), chatCheckResult);
return botService.startPublicChat(
chatRequestParams.getBotId(),
prompt,
chatRequestParams.getMessages(),
chatCheckResult,
buildRuntimeContext(chatCheckResult.getAiBot(), chatRequestParams.getConversationId(), prompt, sysApiKey)
);
}
private ChatRuntimeContext buildRuntimeContext(Bot bot, String conversationId, String prompt, SysApiKey sysApiKey) {
ChatRuntimeContext context = new ChatRuntimeContext();
context.setChannel(ChatChannel.PUBLIC_API);
context.setSessionId(new BigInteger(conversationId));
context.setTenantId(BigInteger.ZERO);
context.setDeptId(BigInteger.ZERO);
context.setUserId(BigInteger.ZERO);
context.setUserAccount("apikey:" + sysApiKey.getId());
context.setUserName("API 调用方");
context.setAssistantId(bot == null ? BigInteger.ZERO : bot.getId());
context.setAssistantCode(bot == null ? null : bot.getAlias());
context.setAssistantName(bot == null ? null : bot.getTitle());
context.setSessionTitle(prompt != null && prompt.length() > 200 ? prompt.substring(0, 200) : prompt);
context.setAnonymous(true);
return context;
}