feat(agent): enforce model readiness and polish selector UX

Block chat when agents lack an explicit chat or rerank model, guide users
through the selector and editor with field highlight, and align session QA
checks with the same readiness rules on backend and frontend.
This commit is contained in:
wizardchen
2026-06-25 21:02:14 +08:00
committed by lyingbug
parent 1e16834d27
commit 9ca4e1f23a
16 changed files with 1247 additions and 673 deletions
@@ -0,0 +1,85 @@
package service
import (
"context"
"testing"
"github.com/Tencent/WeKnora/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestResolveChatModelIDRequiresConfiguredAgentModel(t *testing.T) {
svc := &sessionService{
modelService: &stubModelService{
modelsByID: map[string]*types.Model{
"builtin-chat": {
ID: "builtin-chat",
Type: types.ModelTypeKnowledgeQA,
},
},
},
}
req := &types.QARequest{
Session: &types.Session{},
CustomAgent: &types.CustomAgent{
ID: "agent-1",
},
// Even a valid request-level model must not hide incomplete agent config.
SummaryModelID: "builtin-chat",
}
modelID, err := svc.resolveChatModelID(context.Background(), req, nil, nil)
require.Error(t, err)
assert.Empty(t, modelID)
assert.Contains(t, err.Error(), "model_id")
}
func TestResolveChatModelIDRejectsUnavailableConfiguredAgentModel(t *testing.T) {
svc := &sessionService{
modelService: &stubModelService{modelsByID: map[string]*types.Model{}},
}
req := &types.QARequest{
Session: &types.Session{},
CustomAgent: &types.CustomAgent{
ID: "agent-1",
Config: types.CustomAgentConfig{
ModelID: "deleted-model",
},
},
}
modelID, err := svc.resolveChatModelID(context.Background(), req, nil, nil)
require.Error(t, err)
assert.Empty(t, modelID)
assert.Contains(t, err.Error(), "unavailable")
}
func TestResolveChatModelIDUsesValidConfiguredAgentModel(t *testing.T) {
svc := &sessionService{
modelService: &stubModelService{
modelsByID: map[string]*types.Model{
"agent-chat": {
ID: "agent-chat",
Type: types.ModelTypeKnowledgeQA,
},
},
},
}
req := &types.QARequest{
Session: &types.Session{},
CustomAgent: &types.CustomAgent{
ID: "agent-1",
Config: types.CustomAgentConfig{
ModelID: "agent-chat",
},
},
}
modelID, err := svc.resolveChatModelID(context.Background(), req, nil, nil)
require.NoError(t, err)
assert.Equal(t, "agent-chat", modelID)
}