feat(captain): align task payload persistence
This commit is contained in:
@@ -45,11 +45,11 @@ func (h *CaptainTaskHandler) ReplySuggestion(c *gin.Context) {
|
||||
result, err := h.svc.ReplySuggestion(c.Request.Context(), uint(accountID), &req)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("ReplySuggestion: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to generate reply suggestions")
|
||||
renderCaptainTaskError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
renderCaptainTaskPayload(c, result.Message, result.FollowUpContext)
|
||||
}
|
||||
|
||||
// Summarize generates a concise summary of a conversation.
|
||||
@@ -70,11 +70,11 @@ func (h *CaptainTaskHandler) Summarize(c *gin.Context) {
|
||||
result, err := h.svc.Summarize(c.Request.Context(), uint(accountID), &req)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Summarize: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to summarize conversation")
|
||||
renderCaptainTaskError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
renderCaptainTaskPayload(c, result.Message, result.FollowUpContext)
|
||||
}
|
||||
|
||||
// Rewrite rewrites a draft message to improve tone, clarity, or language.
|
||||
@@ -95,11 +95,11 @@ func (h *CaptainTaskHandler) Rewrite(c *gin.Context) {
|
||||
result, err := h.svc.Rewrite(c.Request.Context(), uint(accountID), &req)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Rewrite: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to rewrite message")
|
||||
renderCaptainTaskError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
renderCaptainTaskPayload(c, result.Message, result.FollowUpContext)
|
||||
}
|
||||
|
||||
// --- SSE Streaming Endpoints (M12) ---
|
||||
@@ -280,3 +280,20 @@ func captainEscapeJSONString(s string) string {
|
||||
}
|
||||
return result.String()
|
||||
}
|
||||
|
||||
func renderCaptainTaskPayload(c *gin.Context, message string, followUpContext map[string]interface{}) {
|
||||
payload := gin.H{"message": message}
|
||||
if followUpContext != nil {
|
||||
payload["follow_up_context"] = followUpContext
|
||||
}
|
||||
c.JSON(http.StatusOK, payload)
|
||||
}
|
||||
|
||||
func renderCaptainTaskError(c *gin.Context, err error) {
|
||||
status, message, ok := service.CaptainTaskErrorStatus(err)
|
||||
if !ok {
|
||||
status = http.StatusUnprocessableEntity
|
||||
message = err.Error()
|
||||
}
|
||||
c.JSON(status, gin.H{"error": message})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user