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:
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<div v-else class="channels-list">
|
<div v-else class="channels-list">
|
||||||
<div v-for="channel in channels" :key="channel.id" class="channel-item">
|
<div v-for="channel in channels" :key="channel.id" class="channel-item">
|
||||||
<div class="channel-info">
|
<div class="channel-item-header">
|
||||||
<div class="channel-info-top">
|
<div class="channel-info-top">
|
||||||
<div class="channel-main">
|
<div class="channel-main">
|
||||||
<span class="platform-badge" :class="channel.platform">
|
<span class="platform-badge" :class="channel.platform">
|
||||||
@@ -28,6 +28,28 @@
|
|||||||
<span class="channel-name">{{ channel.name || $t('agentEditor.im.unnamed') }}</span>
|
<span class="channel-name">{{ channel.name || $t('agentEditor.im.unnamed') }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="channel-actions">
|
||||||
|
<t-switch
|
||||||
|
:value="channel.enabled"
|
||||||
|
size="small"
|
||||||
|
@change="handleToggle(channel)"
|
||||||
|
/>
|
||||||
|
<t-dropdown
|
||||||
|
trigger="click"
|
||||||
|
placement="bottom-right"
|
||||||
|
:options="[
|
||||||
|
{ content: $t('common.edit'), value: 'edit', onClick: () => editChannel(channel) },
|
||||||
|
{ content: $t('common.delete'), value: 'delete', theme: 'error' }
|
||||||
|
]"
|
||||||
|
@click="(data) => data.value === 'delete' && handleDelete(channel.id)"
|
||||||
|
>
|
||||||
|
<t-button variant="text" theme="default" size="small">
|
||||||
|
<t-icon name="more" />
|
||||||
|
</t-button>
|
||||||
|
</t-dropdown>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="channel-info">
|
||||||
<div class="channel-meta">
|
<div class="channel-meta">
|
||||||
<span class="meta-tag">
|
<span class="meta-tag">
|
||||||
<t-icon name="link" class="meta-icon" />
|
<t-icon name="link" class="meta-icon" />
|
||||||
@@ -50,21 +72,6 @@
|
|||||||
</t-button>
|
</t-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="channel-actions">
|
|
||||||
<t-switch
|
|
||||||
:value="channel.enabled"
|
|
||||||
size="small"
|
|
||||||
@change="handleToggle(channel)"
|
|
||||||
/>
|
|
||||||
<t-button variant="text" theme="default" size="small" @click="editChannel(channel)">
|
|
||||||
<t-icon name="edit" />
|
|
||||||
</t-button>
|
|
||||||
<t-popconfirm :content="$t('agentEditor.im.deleteConfirm')" @confirm="handleDelete(channel.id)">
|
|
||||||
<t-button variant="text" theme="danger" size="small">
|
|
||||||
<t-icon name="delete" />
|
|
||||||
</t-button>
|
|
||||||
</t-popconfirm>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -75,29 +82,43 @@
|
|||||||
{{ $t('agentEditor.im.addChannel') }}
|
{{ $t('agentEditor.im.addChannel') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
|
|
||||||
<!-- Create/Edit dialog -->
|
<!-- Create/Edit drawer -->
|
||||||
<t-dialog
|
<t-drawer
|
||||||
v-model:visible="showCreateDialog"
|
v-model:visible="showCreateDialog"
|
||||||
:header="editingChannel ? $t('agentEditor.im.editChannel') : $t('agentEditor.im.addChannel')"
|
:header="editingChannel ? $t('agentEditor.im.editChannel') : $t('agentEditor.im.addChannel')"
|
||||||
:confirm-btn="$t('common.save')"
|
:confirm-btn="$t('common.save')"
|
||||||
:cancel-btn="$t('common.cancel')"
|
:cancel-btn="$t('common.cancel')"
|
||||||
@confirm="handleSave"
|
@confirm="handleSave"
|
||||||
@close="resetForm"
|
@close="resetForm"
|
||||||
width="560px"
|
size="560px"
|
||||||
>
|
>
|
||||||
<div class="dialog-form">
|
<div class="drawer-form">
|
||||||
<!-- Platform -->
|
<!-- Platform -->
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<label class="form-label">{{ $t('agentEditor.im.platform') }}</label>
|
<label class="form-label">{{ $t('agentEditor.im.platform') }}</label>
|
||||||
<t-radio-group v-model="formData.platform" :disabled="!!editingChannel" @change="onPlatformChange">
|
<t-select v-model="formData.platform" :disabled="!!editingChannel" @change="onPlatformChange">
|
||||||
<t-radio-button value="wecom">{{ $t('agentEditor.im.wecom') }}</t-radio-button>
|
<t-option value="wecom" :label="$t('agentEditor.im.wecom')">
|
||||||
<t-radio-button value="feishu">{{ $t('agentEditor.im.feishu') }}</t-radio-button>
|
<span class="platform-badge wecom" style="margin-right: 8px;">{{ $t('agentEditor.im.wecom') }}</span>
|
||||||
<t-radio-button value="slack">{{ $t('agentEditor.im.slack') }}</t-radio-button>
|
</t-option>
|
||||||
<t-radio-button value="telegram">{{ $t('agentEditor.im.telegram') }}</t-radio-button>
|
<t-option value="feishu" :label="$t('agentEditor.im.feishu')">
|
||||||
<t-radio-button value="dingtalk">{{ $t('agentEditor.im.dingtalk') }}</t-radio-button>
|
<span class="platform-badge feishu" style="margin-right: 8px;">{{ $t('agentEditor.im.feishu') }}</span>
|
||||||
<t-radio-button value="mattermost">{{ $t('agentEditor.im.mattermost') }}</t-radio-button>
|
</t-option>
|
||||||
<t-radio-button value="wechat">{{ $t('agentEditor.im.wechat') }}</t-radio-button>
|
<t-option value="slack" :label="$t('agentEditor.im.slack')">
|
||||||
</t-radio-group>
|
<span class="platform-badge slack" style="margin-right: 8px;">{{ $t('agentEditor.im.slack') }}</span>
|
||||||
|
</t-option>
|
||||||
|
<t-option value="telegram" :label="$t('agentEditor.im.telegram')">
|
||||||
|
<span class="platform-badge telegram" style="margin-right: 8px;">{{ $t('agentEditor.im.telegram') }}</span>
|
||||||
|
</t-option>
|
||||||
|
<t-option value="dingtalk" :label="$t('agentEditor.im.dingtalk')">
|
||||||
|
<span class="platform-badge dingtalk" style="margin-right: 8px;">{{ $t('agentEditor.im.dingtalk') }}</span>
|
||||||
|
</t-option>
|
||||||
|
<t-option value="mattermost" :label="$t('agentEditor.im.mattermost')">
|
||||||
|
<span class="platform-badge mattermost" style="margin-right: 8px;">{{ $t('agentEditor.im.mattermost') }}</span>
|
||||||
|
</t-option>
|
||||||
|
<t-option value="wechat" :label="$t('agentEditor.im.wechat')">
|
||||||
|
<span class="platform-badge wechat" style="margin-right: 8px;">{{ $t('agentEditor.im.wechat') }}</span>
|
||||||
|
</t-option>
|
||||||
|
</t-select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Name -->
|
<!-- Name -->
|
||||||
@@ -394,7 +415,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</t-dialog>
|
</t-drawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -766,29 +787,37 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.channels-list {
|
.channels-list {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-direction: column;
|
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||||
gap: 10px;
|
gap: 16px;
|
||||||
max-height: 400px;
|
max-height: 400px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.channel-item {
|
.channel-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
flex-direction: column;
|
||||||
align-items: center;
|
gap: 16px;
|
||||||
gap: 12px;
|
padding: 16px;
|
||||||
padding: 14px 16px;
|
background: var(--td-bg-color-container);
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
border: 1px solid var(--td-component-stroke);
|
border: 1px solid var(--td-component-stroke);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
transition: background 0.2s ease, border-color 0.2s ease;
|
transition: all 0.2s cubic-bezier(0.38, 0, 0.24, 1);
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
border-color: var(--td-brand-color-focus);
|
border-color: var(--td-brand-color);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.channel-item-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
.channel-info {
|
.channel-info {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
@@ -924,7 +953,7 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-form {
|
.drawer-form {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
|
|||||||
@@ -209,7 +209,7 @@
|
|||||||
>
|
>
|
||||||
<div v-html="renderMarkdownContent(event.content)"></div>
|
<div v-html="renderMarkdownContent(event.content)"></div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="event.done" class="answer-toolbar">
|
<div v-if="event.done && event.content && event.content.trim()" class="answer-toolbar">
|
||||||
<t-button size="small" variant="outline" shape="round" @click.stop="handleCopyAnswer(event)" :title="$t('agent.copy')">
|
<t-button size="small" variant="outline" shape="round" @click.stop="handleCopyAnswer(event)" :title="$t('agent.copy')">
|
||||||
<t-icon name="copy" />
|
<t-icon name="copy" />
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -894,6 +894,19 @@ const finalContent = computed(() => {
|
|||||||
return { type: 'answer' };
|
return { type: 'answer' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do NOT fall back to re-rendering the last thinking event when the
|
||||||
|
// intermediate-steps tree already shows it — that would duplicate the
|
||||||
|
// thinking card below the tree. The fallback is only meaningful for
|
||||||
|
// legacy conversations where the tree is absent. Also skip for
|
||||||
|
// user-stopped conversations which have no final answer to fall back to.
|
||||||
|
if (shouldShowCollapsedSteps.value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const wasStopped = stream.some((e: any) => e.type === 'stop');
|
||||||
|
if (wasStopped) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Fallback: if no answer content (legacy path or LLM didn't call final_answer),
|
// Fallback: if no answer content (legacy path or LLM didn't call final_answer),
|
||||||
// use last thinking as final content
|
// use last thinking as final content
|
||||||
const thinkingEvents = stream.filter((e: any) => e.type === 'thinking' && e.content && e.content.trim());
|
const thinkingEvents = stream.filter((e: any) => e.type === 'thinking' && e.content && e.content.trim());
|
||||||
@@ -1071,6 +1084,14 @@ const displayEvents = computed(() => {
|
|||||||
return answerEvents;
|
return answerEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the intermediate-steps tree is active, all thinking/tool_call events
|
||||||
|
// are already rendered there. Showing anything else here would duplicate
|
||||||
|
// them. This covers both the user-stopped case and any completion path
|
||||||
|
// that didn't produce an answer event.
|
||||||
|
if (shouldShowCollapsedSteps.value) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
// Fallback: if no answer events, show last thinking (legacy compatibility)
|
// Fallback: if no answer events, show last thinking (legacy compatibility)
|
||||||
const final = finalContent.value;
|
const final = finalContent.value;
|
||||||
if (!final) {
|
if (!final) {
|
||||||
|
|||||||
@@ -380,15 +380,14 @@ const reconstructEventStreamFromSteps = (agentSteps, messageContent, isCompleted
|
|||||||
if (isFallback) answerEvent.is_fallback = true;
|
if (isFallback) answerEvent.is_fallback = true;
|
||||||
events.push(answerEvent);
|
events.push(answerEvent);
|
||||||
} else if (isCompleted) {
|
} else if (isCompleted) {
|
||||||
// 如果消息已完成但 content 为空(Agent 模式常见情况),添加一个空的 answer 事件标记完成
|
// 消息已完成但 content 为空:说明是"停止时尚未产出最终答案"的场景。
|
||||||
// 这样可以确保 isConversationDone 返回 true,不显示 loading-indicator
|
// Push 一个 stop 事件,让 AgentStreamDisplay 的 isConversationDone 返回 true,
|
||||||
const answerEvent = {
|
// 但不产生 answer 内容,也就不会渲染最终答案的 toolbar。与实时 stop 分支保持一致。
|
||||||
type: 'answer',
|
events.push({
|
||||||
content: '',
|
type: 'stop',
|
||||||
done: true
|
timestamp: Date.now(),
|
||||||
};
|
reason: 'user_requested'
|
||||||
if (isFallback) answerEvent.is_fallback = true;
|
});
|
||||||
events.push(answerEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
@@ -435,11 +434,9 @@ const handleMsgList = async (data, isScrollType = false, newScrollHeight) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只给非Agent模式的空内容已完成消息设置默认错误消息
|
// 非 Agent 模式下若 content 为空(例如用户停止时尚未产出任何文字),
|
||||||
// Agent模式的消息内容在agent_steps中,content为空是正常的
|
// 保持为空;botmsg.vue 会因 hasActualContent=false 不渲染内容区和 toolbar。
|
||||||
if (item.is_completed && !item.content && !item.isAgentMode) {
|
// 此前这里会兜底为 "chat.cannotAnswer",会让停止场景显示误导性文案并出现复制按钮。
|
||||||
item.content = t('chat.cannotAnswer');
|
|
||||||
}
|
|
||||||
messagesList.unshift(item);
|
messagesList.unshift(item);
|
||||||
if (isFirstEnter.value) {
|
if (isFirstEnter.value) {
|
||||||
scrollToBottom(true);
|
scrollToBottom(true);
|
||||||
@@ -726,6 +723,24 @@ onChunk((data) => {
|
|||||||
// 原有的知识库 QA 处理逻辑(非 Agent 模式)
|
// 原有的知识库 QA 处理逻辑(非 Agent 模式)
|
||||||
// answer 内容中可能包含 <think>...</think> 标签
|
// answer 内容中可能包含 <think>...</think> 标签
|
||||||
|
|
||||||
|
// 非 Agent 模式下的 stop 事件:只更新状态,不把后端附带的 "Generation stopped by user"
|
||||||
|
// 文案拼进 content,保留用户点停止时已经流式输出的内容不变。
|
||||||
|
if (data.response_type === 'stop') {
|
||||||
|
console.log('[Stop Event] Non-agent generation stopped');
|
||||||
|
const stoppedMessage = messagesList.findLast((item) => {
|
||||||
|
if (item.request_id === data.id) return true;
|
||||||
|
return item.id === data.id;
|
||||||
|
});
|
||||||
|
if (stoppedMessage) {
|
||||||
|
stoppedMessage.is_completed = true;
|
||||||
|
}
|
||||||
|
loading.value = false;
|
||||||
|
isReplying.value = false;
|
||||||
|
fullContent.value = '';
|
||||||
|
currentAssistantMessageId.value = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 检查消息是否已经完成,如果已完成则忽略后续的完成事件(防止空内容覆盖)
|
// 检查消息是否已经完成,如果已完成则忽略后续的完成事件(防止空内容覆盖)
|
||||||
const existingMessage = messagesList.findLast((item) => {
|
const existingMessage = messagesList.findLast((item) => {
|
||||||
if (item.request_id === data.id) {
|
if (item.request_id === data.id) {
|
||||||
|
|||||||
@@ -353,6 +353,24 @@ func (e *AgentEngine) executeLoop(
|
|||||||
common.PipelineInfo(ctx, "Agent", "loop_start", map[string]interface{}{
|
common.PipelineInfo(ctx, "Agent", "loop_start", map[string]interface{}{
|
||||||
"max_iterations": e.config.MaxIterations,
|
"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
|
emptyRetries := 0
|
||||||
consecutiveSameContent := 0
|
consecutiveSameContent := 0
|
||||||
lastResponseContent := ""
|
lastResponseContent := ""
|
||||||
@@ -393,14 +411,16 @@ loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If loop finished without final answer, generate one
|
// If loop finished without final answer, generate one — but skip this
|
||||||
if !state.IsComplete {
|
// 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)
|
e.handleMaxIterations(ctx, query, state, sessionID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit completion event
|
|
||||||
e.emitCompletionEvent(ctx, state, sessionID, messageID, startTime)
|
|
||||||
|
|
||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,6 +574,25 @@ func (e *AgentEngine) runReActIteration(
|
|||||||
Timestamp: time.Now(),
|
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)
|
// 2. Analyze: Check for stop conditions (natural stop or final_answer tool)
|
||||||
verdict := e.analyzeResponse(ctx, response, step, state.CurrentRound, sessionID, roundStart)
|
verdict := e.analyzeResponse(ctx, response, step, state.CurrentRound, sessionID, roundStart)
|
||||||
if verdict.isDone {
|
if verdict.isDone {
|
||||||
|
|||||||
@@ -213,9 +213,13 @@ func (h *Handler) setupStopEventHandler(
|
|||||||
eventBus.On(event.EventStop, func(ctx context.Context, evt event.Event) error {
|
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)
|
logger.Infof(ctx, "Received stop event, cancelling async operations for session: %s", sessionID)
|
||||||
cancel()
|
cancel()
|
||||||
assistantMessage.Content = "用户停止了本次对话"
|
// 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 session's tenant for message update (ctx may have effectiveTenantID when using shared agent).
|
||||||
updateCtx := context.WithValue(ctx, types.TenantIDContextKey, sessionTenantID)
|
// 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
|
h.completeAssistantMessage(updateCtx, assistantMessage, "") // empty query: stopped conversations are not indexed
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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)
|
// Agent mode: complete the assistant message in defer (normal mode does it via event handler)
|
||||||
if mode == qaModeAgent {
|
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)
|
h.completeAssistantMessage(updateCtx, streamCtx.assistantMessage, reqCtx.query)
|
||||||
logger.Infof(streamCtx.asyncCtx, "Agent QA service completed for session: %s", sessionID)
|
logger.Infof(streamCtx.asyncCtx, "Agent QA service completed for session: %s", sessionID)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user