feat(copilot): move provider configuration to settings

This commit is contained in:
2026-07-12 22:27:29 +08:00
parent f39943629f
commit df23caf7d9
29 changed files with 916 additions and 258 deletions
@@ -83,7 +83,7 @@ func TestCaptainTaskHandler_Summarize_ChatwootRawPayload(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "1"}}
c.Params = gin.Params{{Key: "account_id", Value: "1"}}
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/tasks/summarize", bytes.NewReader([]byte(`{"conversation_display_id":123}`)))
c.Request.Header.Set("Content-Type", "application/json")
@@ -96,12 +96,33 @@ func TestCaptainTaskHandler_Summarize_ChatwootRawPayload(t *testing.T) {
assert.NotContains(t, resp, "success")
}
func TestCaptainTaskHandler_ReplySuggestion_UsesAccountIDRouteParam(t *testing.T) {
provider := &mockCaptainTaskHandlerLLM{response: &llm.ChatResponse{Choices: []llm.ChatChoice{{Message: llm.ChatMessage{Role: "assistant", Content: "Happy to help"}}}}}
handler, db := setupCaptainTaskHandlerTest(t, provider)
displayID := uint(3)
conv := &model.Conversation{AccountID: 1, DisplayID: &displayID, Status: "open", ChannelType: "web_widget", Channel: "web_widget"}
require.NoError(t, db.Create(conv).Error)
require.NoError(t, db.Create(&model.Message{ConversationID: conv.ID, AccountID: 1, SenderType: "contact", MessageType: "incoming", Content: "Need help"}).Error)
router := gin.New()
router.POST("/api/v1/accounts/:account_id/captain/tasks/reply_suggestion", handler.ReplySuggestion)
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/tasks/reply_suggestion", bytes.NewReader([]byte(`{"conversation_display_id":3}`)))
req.Header.Set("Content-Type", "application/json")
router.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Code)
var resp map[string]interface{}
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &resp))
assert.Equal(t, "Happy to help", resp["message"])
}
func TestCaptainTaskHandler_Rewrite_NoProviderRawDisabled(t *testing.T) {
handler, _ := setupCaptainTaskHandlerTest(t, nil)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "1"}}
c.Params = gin.Params{{Key: "account_id", Value: "1"}}
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/tasks/rewrite", bytes.NewReader([]byte(`{"content":"hello","operation":"professional"}`)))
c.Request.Header.Set("Content-Type", "application/json")
@@ -119,7 +140,7 @@ func TestCaptainTaskHandler_StreamRewrite_NoProviderDisabledSSE(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "1"}}
c.Params = gin.Params{{Key: "account_id", Value: "1"}}
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/tasks/rewrite/stream", bytes.NewReader([]byte(`{"content":"hello","operation":"professional"}`)))
c.Request.Header.Set("Content-Type", "application/json")
@@ -146,7 +167,7 @@ func TestCaptainTaskHandler_StreamSummarize_ChatwootDisplayID(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "1"}}
c.Params = gin.Params{{Key: "account_id", Value: "1"}}
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/tasks/summarize/stream", bytes.NewReader([]byte(`{"conversation_display_id":456}`)))
c.Request.Header.Set("Content-Type", "application/json")
@@ -165,7 +186,7 @@ func TestCaptainTaskHandler_StreamRewrite_InvalidOperationSSE(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "1"}}
c.Params = gin.Params{{Key: "account_id", Value: "1"}}
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/tasks/rewrite/stream", strings.NewReader(`{"content":"hello","operation":"pirate"}`))
c.Request.Header.Set("Content-Type", "application/json")