cc 3 ay önce
ebeveyn
işleme
3302a8230d

+ 7 - 3
src/main/java/com/qingjian/module/ai/portal/WebController.java

@@ -17,6 +17,7 @@ package com.qingjian.module.ai.portal;
 
 import cn.hutool.core.io.FileUtil;
 import com.qingjian.common.constants.PathConst;
+import com.qingjian.common.utils.StateManager;
 import lombok.extern.slf4j.Slf4j;
 import org.noear.snack4.ONode;
 import org.noear.solon.annotation.Controller;
@@ -58,7 +59,7 @@ public class WebController {
      */
     @Mapping("/chat/sessions")
     public List<AiSession> sessions() {
-        Path sessionsPath = PathConst.AGENT_PATH.resolve("sessions");
+        Path sessionsPath = PathConst.AGENT_PATH.resolve("sessions").resolve(StateManager.instance().getCaseId().toString());
         File sessionsDir = sessionsPath.toFile();
         List<AiSession> result = new ArrayList<>();
         if (sessionsDir.exists() && sessionsDir.isDirectory()) {
@@ -92,7 +93,8 @@ public class WebController {
         if (sessionId == null || sessionId.isEmpty()) {
             return List.of();
         }
-        Path sessionsPath = PathConst.AGENT_PATH.resolve("sessions").resolve(sessionId);
+        Path caseSession = PathConst.AGENT_PATH.resolve("sessions", StateManager.instance().getCaseId().toString());
+        Path sessionsPath = caseSession.resolve(sessionId);
         File msgFile = new File(sessionsPath.toFile(), sessionId + ".messages.ndjson");
         List<AiMessage> result = new ArrayList<>();
         if (msgFile.exists()) {
@@ -127,7 +129,9 @@ public class WebController {
         if (sessionId == null || sessionId.isEmpty()) {
             return;
         }
-        File sessionDir = PathConst.AGENT_PATH.resolve("sessions").resolve(sessionId).toFile();
+        File sessionDir = PathConst.AGENT_PATH.resolve("sessions")
+                .resolve(StateManager.instance().getCaseId().toString())
+                .resolve(sessionId).toFile();
         if (sessionDir.exists() && sessionDir.isDirectory()) {
             FileUtil.del(sessionDir);
         }

+ 6 - 5
src/main/java/com/qingjian/module/ai/service/AiService.java

@@ -40,7 +40,6 @@ import java.time.Duration;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 
 @Managed
@@ -75,8 +74,11 @@ public class AiService {
 
 
     private final Map<String, AgentSession> sessionMap = new ConcurrentHashMap<>();
-    private final AgentSessionProvider sessionProvider = (sessionId) -> sessionMap.computeIfAbsent(sessionId, key ->
-            new FileAgentSession(key, PathConst.AGENT_PATH.resolve(AgentRuntime.SESSION_PATH, key).toString()));
+    private final AgentSessionProvider sessionProvider = (sessionId) -> sessionMap.computeIfAbsent(sessionId, key -> {
+        List<String> split = StrUtil.split(sessionId, "_");
+        String last = split.getLast();
+        return new FileAgentSession(key, PathConst.AGENT_PATH.resolve(AgentRuntime.SESSION_PATH, last, key).toString());
+    });
 
     public void createModel(AppChatModel model) {
         ChatConfig chatConfig = new ChatConfig();
@@ -143,6 +145,7 @@ public class AiService {
             return Flux.just(message);
         }
         String sessionId = StrUtil.emptyToDefault(chatRequest.getSessionId(), "default_session_id");
+        sessionId = sessionId + "_" + StateManager.instance().getCaseId();
         // 从向量库查询相关历史消息
         List<ChatMessage> messages = buildContextMessage(chatRequest);
         return buildStreamFlux(sessionId, Prompt.of(messages));
@@ -170,8 +173,6 @@ public class AiService {
      */
     private Flux<String> buildStreamFlux(String sessionId, Prompt prompt) {
         AgentRuntime agentRuntime = Singleton.get(AgentRuntime.class);
-        Integer caseId = StateManager.instance().getCaseId();
-        sessionId = sessionId + Objects.requireNonNullElse(caseId, "");
         return agentRuntime.stream(sessionId, prompt)
                 .map(chunk -> {
                     if (chunk instanceof ReasonChunk) {

+ 2 - 0
src/main/java/com/qingjian/module/plat/service/CaseInfoService.java

@@ -81,6 +81,8 @@ public class CaseInfoService extends ServiceImpl<CaseInfoMapper, CaseInfo> {
         String caseDb = RandomUtil.randomString(8) + caseInfo.getId();
         Path casePath = PathConst.WORKSPACE.resolve(caseInfo.getId().toString());
         FileUtil.mkdir(casePath);
+        Path caseSession = PathConst.AGENT_PATH.resolve("sessions").resolve(caseInfo.getId().toString());
+        FileUtil.mkdir(caseSession);
         Path caseDbPath = casePath.resolve(caseDb);
         if (Files.notExists(caseDbPath)) {
             if (Files.notExists(PathConst.BASE_CASE_DB_PATH)) {

+ 4 - 3
src/main/resources/templates/chat.html

@@ -1561,7 +1561,7 @@
     var providerOptions = [
         {providerCode: 'ollama', providerName: 'Ollama'},
         {providerCode: 'qwen', providerName: '阿里云'},
-        {providerCode: 'deepseek', providerName: 'DeepSeek'}
+        {providerCode: 'openai', providerName: 'DeepSeek'}
     ];
     var modelConfigLoading = false;
 
@@ -1915,7 +1915,6 @@
     chatInput.addEventListener('keydown', function(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); } });
     welcomeSendBtn.addEventListener('click', function() { sendMessage(); });
     chatSendBtn.addEventListener('click', function() {
-        debugger
         if (isStreaming && activeSessionId && sessionMap[activeSessionId]) {
             finishStream(sessionMap[activeSessionId]);
         } else {
@@ -2527,7 +2526,9 @@
             sess.silenceTimer = setTimeout(function() {
                 if (sess.isStreaming && !sess.thinkingBlockEl) showInlineThinking(sess);
             }, 1000);
-        } catch (e) {}
+        } catch (e) {
+            console.error('SSE数据解析失败:', raw, e);
+        }
     }
 
     function finishStream(sess) {