generated from VLADIMIR/template
add AnswerService
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
"evening_detective_server/internal/modules/storytelling"
|
||||
"evening_detective_server/internal/repos/actions_repo"
|
||||
"evening_detective_server/internal/services/game_service"
|
||||
"evening_detective_server/internal/services/answer_service"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
@@ -33,7 +33,11 @@ const defaultCallTimeout = 10 * time.Second
|
||||
type GamePlayer interface {
|
||||
GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_model.Game, []actions_repo.Action, error)
|
||||
AddTeamAction(ctx context.Context, teamId int, password, actionCode string, viaMCP bool) error
|
||||
SubmitTeamAnswers(ctx context.Context, teamId int, password string, answers []game_service.Answer) error
|
||||
}
|
||||
|
||||
// AnswerSubmitter сохраняет ответы команды независимо от прохождения истории.
|
||||
type AnswerSubmitter interface {
|
||||
SubmitTeamAnswers(ctx context.Context, teamId int, password string, answers []answer_service.Answer) error
|
||||
}
|
||||
|
||||
// MCPService собирает MCP-сервер с игровыми инструментами. Сервис не
|
||||
@@ -41,12 +45,13 @@ type GamePlayer interface {
|
||||
// пароль явно — либо из ссылки на игру через инструмент connect, либо
|
||||
// напрямую.
|
||||
type MCPService struct {
|
||||
game GamePlayer
|
||||
game GamePlayer
|
||||
answers AnswerSubmitter
|
||||
}
|
||||
|
||||
// NewMCPService создаёт сервис поверх игровых сервисов.
|
||||
func NewMCPService(game GamePlayer) *MCPService {
|
||||
return &MCPService{game: game}
|
||||
func NewMCPService(game GamePlayer, answers AnswerSubmitter) *MCPService {
|
||||
return &MCPService{game: game, answers: answers}
|
||||
}
|
||||
|
||||
// Server собирает и возвращает MCP-сервер с зарегистрированными
|
||||
@@ -283,7 +288,7 @@ func (s *MCPService) handleMakeMove(ctx context.Context, req mcp.CallToolRequest
|
||||
type submitAnswersArgs struct {
|
||||
teamID int64
|
||||
password string
|
||||
answers []game_service.Answer
|
||||
answers []answer_service.Answer
|
||||
}
|
||||
|
||||
// parseSubmitAnswersArgs разбирает аргументы инструмента submit_answers:
|
||||
@@ -303,7 +308,7 @@ func parseSubmitAnswersArgs(args map[string]any) (submitAnswersArgs, error) {
|
||||
if !ok {
|
||||
return submitAnswersArgs{}, fmt.Errorf("требуется answers (массив ответов)")
|
||||
}
|
||||
answers := make([]game_service.Answer, 0, len(rawAnswers))
|
||||
answers := make([]answer_service.Answer, 0, len(rawAnswers))
|
||||
for i, raw := range rawAnswers {
|
||||
item, ok := raw.(map[string]any)
|
||||
if !ok {
|
||||
@@ -314,7 +319,7 @@ func parseSubmitAnswersArgs(args map[string]any) (submitAnswersArgs, error) {
|
||||
if questionCode == "" {
|
||||
return submitAnswersArgs{}, fmt.Errorf("answers[%d]: требуется questionCode", i)
|
||||
}
|
||||
answers = append(answers, game_service.Answer{
|
||||
answers = append(answers, answer_service.Answer{
|
||||
QuestionCode: questionCode,
|
||||
Text: answerText,
|
||||
})
|
||||
@@ -335,7 +340,7 @@ func (s *MCPService) handleSubmitAnswers(ctx context.Context, req mcp.CallToolRe
|
||||
ctx, cancel := context.WithTimeout(ctx, defaultCallTimeout)
|
||||
defer cancel()
|
||||
|
||||
if err := s.game.SubmitTeamAnswers(ctx, int(args.teamID), args.password, args.answers); err != nil {
|
||||
if err := s.answers.SubmitTeamAnswers(ctx, int(args.teamID), args.password, args.answers); err != nil {
|
||||
return mcp.NewToolResultError(fmt.Sprintf("submit_answers: %v", err)), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user