Selaa lähdekoodia

feat:完善AI助手报错信息

Jerry Liang 2 kuukautta sitten
vanhempi
commit
8c66674e9f
1 muutettua tiedostoa jossa 12 lisäystä ja 3 poistoa
  1. 12 3
      service/utils/acp/acp.go

+ 12 - 3
service/utils/acp/acp.go

@@ -42,6 +42,15 @@ type Response struct {
 type RPCError struct {
 	Code    int    `json:"code"`
 	Message string `json:"message"`
+	Data    string `json:"data,omitempty"`
+}
+
+// FullMessage 返回包含 data 的完整错误信息
+func (e *RPCError) FullMessage() string {
+	if e.Data != "" {
+		return fmt.Sprintf("%s: %s", e.Message, e.Data)
+	}
+	return e.Message
 }
 
 // ============ ACP 协议类型 ============
@@ -385,7 +394,7 @@ func (c *Client) LoadSession(sessionId string, cwd string) (string, string, []Re
 			if numId == id {
 				// session/load 完成
 				if msg.Error != nil {
-					return "", "", nil, fmt.Errorf("session/load 错误: %s", msg.Error.Message)
+					return "", "", nil, fmt.Errorf("session/load 错误: %s", msg.Error.FullMessage())
 				}
 				c.sessionId = sessionId
 				// 追加最后一条未关闭的消息
@@ -526,7 +535,7 @@ func (c *Client) Prompt(sessionId string, message string, eventCh chan<- Event)
 			}
 			var result PromptResult
 			if msg.Error != nil {
-				eventCh <- Event{Type: "error", Content: msg.Error.Message}
+				eventCh <- Event{Type: "error", Content: msg.Error.FullMessage()}
 			} else if err := json.Unmarshal(msg.Result, &result); err == nil {
 				eventCh <- Event{Type: "done", SessionId: sessionId, StopReason: result.StopReason}
 			}
@@ -676,7 +685,7 @@ func (c *Client) sendAndWait(method string, params any) (json.RawMessage, error)
 		// 匹配 ID 的响应
 		if resp.ID != nil && *resp.ID == id {
 			if resp.Error != nil {
-				return nil, fmt.Errorf("ACP 错误 [%d]: %s", resp.Error.Code, resp.Error.Message)
+				return nil, fmt.Errorf("ACP 错误 [%d]: %s", resp.Error.Code, resp.Error.FullMessage())
 			}
 			return resp.Result, nil
 		}