feat(dingtalk): enable secure multimodal image QA

This commit is contained in:
姚章浩
2026-07-16 00:17:16 +08:00
parent 4022040e98
commit c9c4f0aaa5
59 changed files with 3279 additions and 429 deletions
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"github.com/Tencent/WeKnora/internal/agent/tools"
"github.com/Tencent/WeKnora/internal/event"
@@ -156,21 +157,18 @@ func (s *sessionService) AgentQA(
return err
}
// Route image data based on agent model's vision capability
var agentModelSupportsVision bool
if effectiveModelID != "" {
if modelInfo, err := s.modelService.GetModelByID(ctx, effectiveModelID); err == nil && modelInfo != nil {
agentModelSupportsVision = modelInfo.Parameters.SupportsVision
}
}
// The resolved concrete transport is authoritative. Stored model metadata can
// be stale (notably older WeKnora Cloud records), while unknown transports
// still fail closed through SupportsImageInput.
agentModelSupportsVision := modelSupportsDirectImages(summaryModel)
agentQuery := req.Query
var agentImageURLs []string
if agentModelSupportsVision && len(req.ImageURLs) > 0 {
agentImageURLs = req.ImageURLs
agentQuery, agentImageURLs, err := prepareAgentImageInput(ctx, req, agentModelSupportsVision, s.modelService)
if err != nil {
return err
}
if len(agentImageURLs) > 0 {
logger.Infof(ctx, "Agent model supports vision, passing %d image(s) directly", len(agentImageURLs))
} else if req.ImageDescription != "" {
agentQuery = req.Query + "\n\n[用户上传图片内容]\n" + req.ImageDescription
logger.Infof(ctx, "Agent model does not support vision, appending image description (%d chars)", len(req.ImageDescription))
}
if req.QuotedContext != "" {
@@ -208,6 +206,22 @@ func (s *sessionService) AgentQA(
return nil
}
func routeAgentImageInput(req *types.QARequest, modelSupportsVision bool) (string, []string, error) {
if req == nil {
return "", nil, errors.New("QA request is required")
}
if len(req.ImageURLs) == 0 {
return req.Query, nil, nil
}
if modelSupportsVision {
return req.Query, req.ImageURLs, nil
}
if strings.TrimSpace(req.ImageDescription) != "" {
return req.Query + "\n\n[用户上传图片内容]\n" + req.ImageDescription, nil, nil
}
return "", nil, errors.New("agent model does not support visual input and no image description is available")
}
// buildAgentConfig creates a runtime AgentConfig from the QARequest's custom agent configuration,
// tenant info, and resolved knowledge bases / search targets.
func (s *sessionService) buildAgentConfig(