feat(channel): add channel support across various components and locales
- Introduced a new `channel` field in multiple request and message structures to track the source channel (e.g., "web", "api", "im"). - Updated frontend API calls and chat components to include the `channel` parameter, ensuring consistent channel tracking in user messages. - Enhanced localization files to support channel labels in English, Korean, Russian, and Chinese. - Added database migration scripts to incorporate the `channel` column in the messages table, facilitating the storage of channel information. - Refactored related functions and components to accommodate the new channel feature, improving overall message context and tracking.
This commit is contained in:
@@ -165,7 +165,7 @@ func createAgentQueryEvent(sessionID, assistantMessageID string) interfaces.Stre
|
||||
}
|
||||
|
||||
// createUserMessage creates a user message and returns the created message.
|
||||
func (h *Handler) createUserMessage(ctx context.Context, sessionID, query, requestID string, mentionedItems types.MentionedItems, images types.MessageImages) (*types.Message, error) {
|
||||
func (h *Handler) createUserMessage(ctx context.Context, sessionID, query, requestID string, mentionedItems types.MentionedItems, images types.MessageImages, channel string) (*types.Message, error) {
|
||||
return h.messageService.CreateMessage(ctx, &types.Message{
|
||||
SessionID: sessionID,
|
||||
Role: "user",
|
||||
@@ -175,6 +175,7 @@ func (h *Handler) createUserMessage(ctx context.Context, sessionID, query, reque
|
||||
IsCompleted: true,
|
||||
MentionedItems: mentionedItems,
|
||||
Images: images,
|
||||
Channel: channel,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ type qaRequestContext struct {
|
||||
effectiveTenantID uint64 // when using shared agent, tenant ID for model/KB/MCP resolution; 0 = use context tenant
|
||||
images []ImageAttachment // Uploaded images with analysis text
|
||||
userMessageID string // Created user message ID (populated after createUserMessage)
|
||||
channel string // Source channel: "web", "api", "im", etc.
|
||||
}
|
||||
|
||||
// buildQARequest converts the qaRequestContext into a types.QARequest for service invocation.
|
||||
@@ -148,6 +149,7 @@ func (h *Handler) parseQARequest(c *gin.Context, logPrefix string) (*qaRequestCo
|
||||
Role: "assistant",
|
||||
RequestID: c.GetString(types.RequestIDContextKey.String()),
|
||||
IsCompleted: false,
|
||||
Channel: request.Channel,
|
||||
},
|
||||
knowledgeBaseIDs: secutils.SanitizeForLogArray(kbIDs),
|
||||
knowledgeIDs: secutils.SanitizeForLogArray(knowledgeIDs),
|
||||
@@ -157,6 +159,7 @@ func (h *Handler) parseQARequest(c *gin.Context, logPrefix string) (*qaRequestCo
|
||||
mentionedItems: convertMentionedItems(request.MentionedItems),
|
||||
effectiveTenantID: effectiveTenantID,
|
||||
images: request.Images,
|
||||
channel: request.Channel,
|
||||
}
|
||||
|
||||
return reqCtx, &request, nil
|
||||
@@ -475,7 +478,7 @@ func (h *Handler) executeQA(reqCtx *qaRequestContext, mode qaMode, generateTitle
|
||||
}
|
||||
|
||||
// Create user message
|
||||
userMsg, err := h.createUserMessage(ctx, sessionID, reqCtx.query, reqCtx.requestID, reqCtx.mentionedItems, convertImageAttachments(reqCtx.images))
|
||||
userMsg, err := h.createUserMessage(ctx, sessionID, reqCtx.query, reqCtx.requestID, reqCtx.mentionedItems, convertImageAttachments(reqCtx.images), reqCtx.channel)
|
||||
if err != nil {
|
||||
reqCtx.c.Error(errors.NewInternalServerError(err.Error()))
|
||||
return
|
||||
|
||||
@@ -49,6 +49,7 @@ type CreateKnowledgeQARequest struct {
|
||||
DisableTitle bool `json:"disable_title"` // Whether to disable auto title generation
|
||||
EnableMemory bool `json:"enable_memory"` // Whether memory feature is enabled for this request
|
||||
Images []ImageAttachment `json:"images"` // Attached images for multimodal chat
|
||||
Channel string `json:"channel"` // Source channel: "web", "api", "im", etc.
|
||||
}
|
||||
|
||||
// SearchKnowledgeRequest defines the request structure for searching knowledge without LLM summarization
|
||||
|
||||
@@ -1424,6 +1424,7 @@ func (s *Service) handleMessageStream(ctx context.Context, msg *IncomingMessage,
|
||||
userMsg, err := s.messageService.CreateMessage(qaCtx, &types.Message{
|
||||
SessionID: session.ID, Role: "user", Content: msg.Content,
|
||||
RequestID: requestID, CreatedAt: time.Now(), IsCompleted: true,
|
||||
Channel: "im",
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("create user message: %w", err)
|
||||
@@ -1433,6 +1434,7 @@ func (s *Service) handleMessageStream(ctx context.Context, msg *IncomingMessage,
|
||||
assistantMsg, err := s.messageService.CreateMessage(qaCtx, &types.Message{
|
||||
SessionID: session.ID, Role: "assistant",
|
||||
RequestID: requestID, CreatedAt: time.Now(), IsCompleted: false,
|
||||
Channel: "im",
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("create assistant message: %w", err)
|
||||
@@ -1611,6 +1613,7 @@ func (s *Service) runQA(ctx context.Context, session *types.Session, query strin
|
||||
RequestID: requestID,
|
||||
CreatedAt: time.Now(),
|
||||
IsCompleted: true,
|
||||
Channel: "im",
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("create user message: %w", err)
|
||||
@@ -1623,6 +1626,7 @@ func (s *Service) runQA(ctx context.Context, session *types.Session, query strin
|
||||
RequestID: requestID,
|
||||
CreatedAt: time.Now(),
|
||||
IsCompleted: false,
|
||||
Channel: "im",
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("create assistant message: %w", err)
|
||||
|
||||
@@ -125,6 +125,8 @@ type Message struct {
|
||||
IsFallback bool `json:"is_fallback,omitempty"`
|
||||
// Agent total execution duration in milliseconds (from query start to answer start)
|
||||
AgentDurationMs int64 `json:"agent_duration_ms,omitempty" gorm:"column:agent_duration_ms;default:0"`
|
||||
// Channel indicates the source channel of this message (e.g., "web", "api", "im")
|
||||
Channel string `json:"channel,omitempty" gorm:"type:varchar(50);default:''"`
|
||||
// KnowledgeID links this message to a Knowledge entry in the chat history knowledge base
|
||||
// Used for vector search indexing: when set, the message content has been indexed as a Knowledge passage
|
||||
KnowledgeID string `json:"knowledge_id,omitempty" gorm:"type:varchar(36);index"`
|
||||
|
||||
Reference in New Issue
Block a user