feat(ui): refactor IM channels list layout and form\n\n- Change IM channel form from dialog to drawer for better UX\n- Convert channel list from vertical layout to responsive grid cards\n- Move edit/delete actions into a dropdown menu for cleaner card design\n- Replace platform radio group with a select dropdown in the add channel form

This commit is contained in:
wizardchen
2026-04-29 17:04:51 +08:00
committed by lyingbug
parent c62ff4c906
commit da90867dd4
6 changed files with 182 additions and 66 deletions
+44 -5
View File
@@ -353,6 +353,24 @@ func (e *AgentEngine) executeLoop(
common.PipelineInfo(ctx, "Agent", "loop_start", map[string]interface{}{
"max_iterations": e.config.MaxIterations,
})
// Guarantee exactly-one EventAgentComplete emission on every exit path
// (normal finish, ctx cancel observed at the loop head, or iteration error
// bubbling up while ctx was cancelled). The emission triggers
// agent_stream_handler.handleComplete, which is where state.RoundSteps
// (thinking + tool_call history) gets written onto assistantMessage.AgentSteps
// so it can be persisted by the caller's defer. Use WithoutCancel so a
// cancelled ctx does not short-circuit the emit on the stop path.
completionEmitted := false
emitCompletion := func() {
if completionEmitted {
return
}
completionEmitted = true
e.emitCompletionEvent(context.WithoutCancel(ctx), state, sessionID, messageID, startTime)
}
defer emitCompletion()
emptyRetries := 0
consecutiveSameContent := 0
lastResponseContent := ""
@@ -393,14 +411,16 @@ loop:
}
}
// If loop finished without final answer, generate one
if !state.IsComplete {
// If loop finished without final answer, generate one — but skip this
// when the context was cancelled (user pressed stop). In that case the
// fallback LLM call would fail on the already-cancelled ctx and set
// state.FinalAnswer to the generic "Sorry, I was unable to generate a
// complete answer." message, which then leaks to the UI as the final
// answer for a conversation the user deliberately stopped.
if !state.IsComplete && ctx.Err() == nil {
e.handleMaxIterations(ctx, query, state, sessionID)
}
// Emit completion event
e.emitCompletionEvent(ctx, state, sessionID, messageID, startTime)
return state, nil
}
@@ -554,6 +574,25 @@ func (e *AgentEngine) runReActIteration(
Timestamp: time.Now(),
}
// If the request was cancelled while the LLM was streaming (e.g. the
// user pressed "stop"), the stream driver still returns a usable
// response (partial content / finish_reason="stop" / no tool calls).
// Do NOT let analyzeResponse treat that partial thinking text as the
// final answer — it would pollute Message.Content with mid-stream
// thinking and show up as a duplicate card next to the intermediate-
// steps tree. Preserve the partial thinking as an AgentStep and break
// out of the loop without marking state.IsComplete. executeLoop's
// deferred emitCompletionEvent will persist the step onto
// Message.AgentSteps so it still appears in the tree on refresh.
if ctx.Err() != nil {
logger.Warnf(ctx, "[Agent][Round-%d] Context cancelled during LLM call; preserving partial step",
round)
if step.Thought != "" || len(step.ToolCalls) > 0 {
state.RoundSteps = append(state.RoundSteps, step)
}
return iterOutcomeBreak, nil
}
// 2. Analyze: Check for stop conditions (natural stop or final_answer tool)
verdict := e.analyzeResponse(ctx, response, step, state.CurrentRound, sessionID, roundStart)
if verdict.isDone {
+7 -3
View File
@@ -213,9 +213,13 @@ func (h *Handler) setupStopEventHandler(
eventBus.On(event.EventStop, func(ctx context.Context, evt event.Event) error {
logger.Infof(ctx, "Received stop event, cancelling async operations for session: %s", sessionID)
cancel()
assistantMessage.Content = "用户停止了本次对话"
// Use session's tenant for message update (ctx may have effectiveTenantID when using shared agent)
updateCtx := context.WithValue(ctx, types.TenantIDContextKey, sessionTenantID)
// Preserve whatever has been streamed so far; do not overwrite Content.
// Use session's tenant for message update (ctx may have effectiveTenantID when using shared agent).
// Use WithoutCancel so the GORM UPDATE survives the upcoming ctx.Done triggered by cancel()/client disconnect.
updateCtx := context.WithValue(
context.WithoutCancel(ctx),
types.TenantIDContextKey, sessionTenantID,
)
h.completeAssistantMessage(updateCtx, assistantMessage, "") // empty query: stopped conversations are not indexed
return nil
})
+9 -1
View File
@@ -615,7 +615,15 @@ func (h *Handler) executeQA(reqCtx *qaRequestContext, mode qaMode, generateTitle
}
// Agent mode: complete the assistant message in defer (normal mode does it via event handler)
if mode == qaModeAgent {
updateCtx := context.WithValue(streamCtx.asyncCtx, types.TenantIDContextKey, reqCtx.session.TenantID)
// Use WithoutCancel so a user-triggered stop (which cancels
// asyncCtx) doesn't also cancel the GORM UPDATE that persists
// AgentSteps/Content. Without this, cancelled-ctx makes
// GORM skip the write and the agent's intermediate steps
// (thinking / tool_call history) are lost on page refresh.
updateCtx := context.WithValue(
context.WithoutCancel(streamCtx.asyncCtx),
types.TenantIDContextKey, reqCtx.session.TenantID,
)
h.completeAssistantMessage(updateCtx, streamCtx.assistantMessage, reqCtx.query)
logger.Infof(streamCtx.asyncCtx, "Agent QA service completed for session: %s", sessionID)
}