2025-03-31 22:32:19 +08:00
|
|
|
|
<template>
|
2026-01-15 04:54:53 +08:00
|
|
|
|
<div class="chat-container">
|
2025-05-15 22:34:32 +08:00
|
|
|
|
<ChatSidebarComponent
|
|
|
|
|
|
:current-chat-id="currentChatId"
|
|
|
|
|
|
:chats-list="chatsList"
|
2025-11-08 13:59:56 +08:00
|
|
|
|
:is-sidebar-open="chatUIStore.isSidebarOpen"
|
|
|
|
|
|
:is-initial-render="localUIState.isInitialRender"
|
2025-08-11 21:29:33 +08:00
|
|
|
|
:single-mode="props.singleMode"
|
|
|
|
|
|
:agents="agents"
|
2025-08-31 14:39:28 +08:00
|
|
|
|
:selected-agent-id="currentAgentId"
|
2025-11-08 13:59:56 +08:00
|
|
|
|
:is-creating-new-chat="chatUIStore.creatingNewChat"
|
2026-03-06 10:14:43 +08:00
|
|
|
|
:has-more-chats="hasMoreChats"
|
|
|
|
|
|
:is-loading-more="isLoadingMoreChats"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
@create-chat="createNewChat"
|
|
|
|
|
|
@select-chat="selectChat"
|
|
|
|
|
|
@delete-chat="deleteChat"
|
|
|
|
|
|
@rename-chat="renameChat"
|
2026-03-06 20:29:58 +08:00
|
|
|
|
@toggle-pin="togglePinChat"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
@toggle-sidebar="toggleSidebar"
|
2025-08-11 21:29:33 +08:00
|
|
|
|
@open-agent-modal="openAgentModal"
|
2026-03-06 10:14:43 +08:00
|
|
|
|
@load-more-chats="loadMoreChats"
|
2025-06-22 19:49:42 +08:00
|
|
|
|
:class="{
|
2025-11-08 13:59:56 +08:00
|
|
|
|
'sidebar-open': chatUIStore.isSidebarOpen,
|
2026-01-15 04:54:53 +08:00
|
|
|
|
'no-transition': localUIState.isInitialRender
|
2025-06-22 19:49:42 +08:00
|
|
|
|
}"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
/>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
<div class="chat">
|
|
|
|
|
|
<div class="chat-header">
|
|
|
|
|
|
<div class="header__left">
|
2025-04-01 22:16:07 +08:00
|
|
|
|
<slot name="header-left" class="nav-btn"></slot>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<div
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="agent-nav-btn"
|
|
|
|
|
|
v-if="!chatUIStore.isSidebarOpen"
|
|
|
|
|
|
@click="toggleSidebar"
|
|
|
|
|
|
>
|
|
|
|
|
|
<PanelLeftOpen class="nav-btn-icon" size="18" />
|
2025-05-15 22:34:32 +08:00
|
|
|
|
</div>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<div
|
2025-11-08 17:14:54 +08:00
|
|
|
|
type="button"
|
|
|
|
|
|
class="agent-nav-btn"
|
|
|
|
|
|
v-if="!chatUIStore.isSidebarOpen"
|
|
|
|
|
|
:class="{ 'is-disabled': chatUIStore.creatingNewChat }"
|
|
|
|
|
|
@click="createNewChat"
|
|
|
|
|
|
>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<LoaderCircle
|
|
|
|
|
|
v-if="chatUIStore.creatingNewChat"
|
|
|
|
|
|
class="nav-btn-icon loading-icon"
|
|
|
|
|
|
size="18"
|
|
|
|
|
|
/>
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<MessageCirclePlus v-else class="nav-btn-icon" size="16" />
|
2026-01-15 04:54:53 +08:00
|
|
|
|
<span class="text">新对话</span>
|
2025-03-31 23:02:05 +08:00
|
|
|
|
</div>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<div v-if="!props.singleMode" class="agent-nav-btn" @click="openAgentModal">
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<LoaderCircle v-if="!currentAgent" class="nav-btn-icon loading-icon" size="18" />
|
|
|
|
|
|
<Bot v-else :size="18" class="nav-btn-icon" />
|
|
|
|
|
|
<span class="text hide-text">
|
|
|
|
|
|
{{ currentAgentName || '选择智能体' }}
|
|
|
|
|
|
</span>
|
2025-11-23 19:42:51 +08:00
|
|
|
|
<ChevronDown size="16" class="switch-icon" />
|
|
|
|
|
|
</div>
|
2025-03-31 23:02:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="header__right">
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<!-- AgentState 显示按钮已移动到输入框底部 -->
|
2026-01-15 04:54:53 +08:00
|
|
|
|
<slot name="header-right"></slot>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<div class="chat-content-container">
|
|
|
|
|
|
<!-- Main Chat Area -->
|
|
|
|
|
|
<div class="chat-main" ref="chatMainContainer">
|
|
|
|
|
|
<div class="chat-box" ref="messagesContainer">
|
|
|
|
|
|
<div class="conv-box" v-for="(conv, index) in conversations" :key="index">
|
|
|
|
|
|
<AgentMessageComponent
|
|
|
|
|
|
v-for="(message, msgIndex) in conv.messages"
|
|
|
|
|
|
:message="message"
|
|
|
|
|
|
:key="msgIndex"
|
|
|
|
|
|
:is-processing="
|
|
|
|
|
|
isProcessing &&
|
|
|
|
|
|
conv.status === 'streaming' &&
|
|
|
|
|
|
msgIndex === conv.messages.length - 1
|
|
|
|
|
|
"
|
|
|
|
|
|
:show-refs="showMsgRefs(message)"
|
|
|
|
|
|
@retry="retryMessage(message)"
|
|
|
|
|
|
>
|
|
|
|
|
|
</AgentMessageComponent>
|
|
|
|
|
|
<!-- 显示对话最后一个消息使用的模型 -->
|
|
|
|
|
|
<RefsComponent
|
|
|
|
|
|
v-if="shouldShowRefs(conv)"
|
|
|
|
|
|
:message="getLastMessage(conv)"
|
2026-03-02 21:01:37 +08:00
|
|
|
|
:show-refs="['model', 'copy', 'sources']"
|
2026-01-24 15:24:25 +08:00
|
|
|
|
:is-latest-message="false"
|
2026-02-24 14:22:11 +08:00
|
|
|
|
:sources="getConversationSources(conv)"
|
|
|
|
|
|
/>
|
2026-01-24 15:24:25 +08:00
|
|
|
|
</div>
|
2025-06-24 00:15:51 +08:00
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<!-- 生成中的加载状态 - 增强条件支持主聊天和resume流程 -->
|
|
|
|
|
|
<div class="generating-status" v-if="isProcessing && conversations.length > 0">
|
|
|
|
|
|
<div class="generating-indicator">
|
|
|
|
|
|
<div class="loading-dots">
|
|
|
|
|
|
<div></div>
|
|
|
|
|
|
<div></div>
|
|
|
|
|
|
<div></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span class="generating-text">正在生成回复...</span>
|
|
|
|
|
|
</div>
|
2025-06-24 00:15:51 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<div class="bottom" :class="{ 'start-screen': !conversations.length }">
|
|
|
|
|
|
<!-- 人工审批弹窗 - 放在输入框上方 -->
|
|
|
|
|
|
<HumanApprovalModal
|
|
|
|
|
|
:visible="approvalState.showModal"
|
|
|
|
|
|
:question="approvalState.question"
|
|
|
|
|
|
:operation="approvalState.operation"
|
2026-03-07 23:28:25 +08:00
|
|
|
|
:options="approvalState.options"
|
|
|
|
|
|
:multi-select="approvalState.multiSelect"
|
|
|
|
|
|
:allow-other="approvalState.allowOther"
|
|
|
|
|
|
@submit="handleQuestionSubmit"
|
|
|
|
|
|
@cancel="handleQuestionCancel"
|
2026-01-24 15:24:25 +08:00
|
|
|
|
/>
|
2025-12-19 04:04:48 +08:00
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<div class="message-input-wrapper">
|
2026-02-02 21:44:10 +08:00
|
|
|
|
<!-- 加载状态:加载消息 -->
|
|
|
|
|
|
<div v-if="isLoadingMessages" class="chat-loading">
|
|
|
|
|
|
<div class="loading-spinner"></div>
|
|
|
|
|
|
<span>正在加载消息...</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 打招呼区域 - 在输入框上方 -->
|
|
|
|
|
|
<div v-if="!conversations.length" class="chat-examples-input">
|
|
|
|
|
|
<h1>👋 您好,我是{{ currentAgentName }}!</h1>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<AgentInputArea
|
|
|
|
|
|
ref="messageInputRef"
|
|
|
|
|
|
v-model="userInput"
|
|
|
|
|
|
:is-loading="isProcessing"
|
|
|
|
|
|
:disabled="!currentAgent"
|
|
|
|
|
|
:send-button-disabled="(!userInput || !currentAgent) && !isProcessing"
|
|
|
|
|
|
placeholder="输入问题..."
|
|
|
|
|
|
:supports-file-upload="supportsFileUpload"
|
|
|
|
|
|
:agent-id="currentAgentId"
|
|
|
|
|
|
:thread-id="currentChatId"
|
|
|
|
|
|
:ensure-thread="ensureActiveThread"
|
|
|
|
|
|
:has-state-content="hasAgentStateContent"
|
|
|
|
|
|
:is-panel-open="isAgentPanelOpen"
|
2026-02-04 17:05:26 +08:00
|
|
|
|
:mention="mentionConfig"
|
2026-01-24 15:24:25 +08:00
|
|
|
|
@send="handleSendOrStop"
|
|
|
|
|
|
@attachment-changed="handleAgentStateRefresh"
|
|
|
|
|
|
@toggle-panel="toggleAgentPanel"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 示例问题 -->
|
2025-12-19 04:04:48 +08:00
|
|
|
|
<div
|
2026-01-24 15:24:25 +08:00
|
|
|
|
class="example-questions"
|
|
|
|
|
|
v-if="!conversations.length && exampleQuestions.length > 0"
|
2025-12-19 04:04:48 +08:00
|
|
|
|
>
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<div class="example-chips">
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="question in exampleQuestions"
|
|
|
|
|
|
:key="question.id"
|
|
|
|
|
|
class="example-chip"
|
|
|
|
|
|
@click="handleExampleClick(question.text)"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ question.text }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="bottom-actions" v-else>
|
|
|
|
|
|
<p class="note">请注意辨别内容的可靠性</p>
|
2025-12-19 04:04:48 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-01-24 15:24:25 +08:00
|
|
|
|
</div>
|
2025-12-19 04:04:48 +08:00
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
<!-- Agent Panel Area -->
|
|
|
|
|
|
|
2026-02-02 21:44:10 +08:00
|
|
|
|
<div
|
|
|
|
|
|
class="agent-panel-wrapper"
|
|
|
|
|
|
ref="panelWrapperRef"
|
|
|
|
|
|
:class="{
|
|
|
|
|
|
'is-visible': isAgentPanelOpen && hasAgentStateContent,
|
|
|
|
|
|
'no-transition': isResizing
|
|
|
|
|
|
}"
|
|
|
|
|
|
:style="{
|
|
|
|
|
|
flexBasis: isAgentPanelOpen && hasAgentStateContent ? `${panelRatio * 100}%` : '0px'
|
|
|
|
|
|
}"
|
|
|
|
|
|
>
|
|
|
|
|
|
<AgentPanel
|
2026-01-31 17:04:30 +08:00
|
|
|
|
v-if="isAgentPanelOpen && hasAgentStateContent"
|
2026-02-02 21:44:10 +08:00
|
|
|
|
:agent-state="currentAgentState"
|
2026-03-04 08:53:50 +08:00
|
|
|
|
:thread-files="currentThreadFiles"
|
2026-02-02 21:44:10 +08:00
|
|
|
|
:thread-id="currentChatId"
|
|
|
|
|
|
:panel-ratio="panelRatio"
|
|
|
|
|
|
@refresh="handleAgentStateRefresh"
|
|
|
|
|
|
@close="toggleAgentPanel"
|
|
|
|
|
|
@resize="handlePanelResize"
|
|
|
|
|
|
@resizing="handleResizingChange"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
</div>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
import { ref, reactive, onMounted, watch, nextTick, computed, onUnmounted } from 'vue'
|
|
|
|
|
|
import { message } from 'ant-design-vue'
|
2025-12-19 04:04:48 +08:00
|
|
|
|
import AgentInputArea from '@/components/AgentInputArea.vue'
|
2025-05-15 22:34:32 +08:00
|
|
|
|
import AgentMessageComponent from '@/components/AgentMessageComponent.vue'
|
|
|
|
|
|
import ChatSidebarComponent from '@/components/ChatSidebarComponent.vue'
|
2025-06-24 00:15:51 +08:00
|
|
|
|
import RefsComponent from '@/components/RefsComponent.vue'
|
2026-01-24 15:24:25 +08:00
|
|
|
|
import { PanelLeftOpen, MessageCirclePlus, LoaderCircle, ChevronDown, Bot } from 'lucide-vue-next'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
import { handleChatError, handleValidationError } from '@/utils/errorHandler'
|
|
|
|
|
|
import { ScrollController } from '@/utils/scrollController'
|
|
|
|
|
|
import { AgentValidator } from '@/utils/agentValidator'
|
|
|
|
|
|
import { useAgentStore } from '@/stores/agent'
|
|
|
|
|
|
import { useChatUIStore } from '@/stores/chatUI'
|
|
|
|
|
|
import { storeToRefs } from 'pinia'
|
|
|
|
|
|
import { MessageProcessor } from '@/utils/messageProcessor'
|
2026-02-04 17:05:26 +08:00
|
|
|
|
import { agentApi, threadApi, databaseApi, mcpApi } from '@/apis'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
import HumanApprovalModal from '@/components/HumanApprovalModal.vue'
|
|
|
|
|
|
import { useApproval } from '@/composables/useApproval'
|
|
|
|
|
|
import { useAgentStreamHandler } from '@/composables/useAgentStreamHandler'
|
2026-01-24 15:24:25 +08:00
|
|
|
|
import AgentPanel from '@/components/AgentPanel.vue'
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== PROPS & EMITS ====================
|
2025-03-31 23:02:05 +08:00
|
|
|
|
const props = defineProps({
|
2025-08-31 12:22:49 +08:00
|
|
|
|
agentId: { type: String, default: '' },
|
2025-08-25 13:57:47 +08:00
|
|
|
|
singleMode: { type: Boolean, default: true }
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
|
|
|
|
|
const emit = defineEmits(['open-config', 'open-agent-modal'])
|
2025-08-11 21:29:33 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== STORE MANAGEMENT ====================
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const agentStore = useAgentStore()
|
|
|
|
|
|
const chatUIStore = useChatUIStore()
|
2026-02-04 17:05:26 +08:00
|
|
|
|
const {
|
|
|
|
|
|
agents,
|
|
|
|
|
|
selectedAgentId,
|
|
|
|
|
|
defaultAgentId,
|
|
|
|
|
|
selectedAgentConfigId,
|
|
|
|
|
|
agentConfig,
|
2026-03-02 21:01:37 +08:00
|
|
|
|
configurableItems,
|
|
|
|
|
|
availableKnowledgeBases,
|
|
|
|
|
|
availableMcps
|
2026-02-04 17:05:26 +08:00
|
|
|
|
} = storeToRefs(agentStore)
|
2025-08-25 01:46:31 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// ==================== LOCAL CHAT & UI STATE ====================
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const userInput = ref('')
|
2026-02-25 16:26:09 +08:00
|
|
|
|
const useRunsApi =
|
|
|
|
|
|
import.meta.env.VITE_USE_RUNS_API === 'true' &&
|
|
|
|
|
|
localStorage.getItem('force_legacy_stream') !== 'true'
|
|
|
|
|
|
|
|
|
|
|
|
const ACTIVE_RUN_STORAGE_TTL_MS = 60 * 60 * 1000
|
|
|
|
|
|
const ACTIVE_RUN_CLIENT_ID = `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
|
|
|
|
|
|
const typingChunkQueue = []
|
|
|
|
|
|
let typingAnimationFrameId = null
|
|
|
|
|
|
let typingLastFrameTs = 0
|
|
|
|
|
|
let pendingTypingChars = 0
|
|
|
|
|
|
const MIN_TYPING_CPS = 32
|
|
|
|
|
|
const MAX_TYPING_CPS = 320
|
|
|
|
|
|
const TYPING_BACKLOG_HIGH_WATERMARK = 500
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-09-09 20:25:48 +08:00
|
|
|
|
// 从智能体元数据获取示例问题
|
|
|
|
|
|
const exampleQuestions = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const agentId = currentAgentId.value
|
|
|
|
|
|
let examples = []
|
2025-11-07 12:28:58 +08:00
|
|
|
|
if (agentId && agents.value && agents.value.length > 0) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const agent = agents.value.find((a) => a.id === agentId)
|
|
|
|
|
|
examples = agent ? agent.examples || [] : []
|
2025-11-07 12:28:58 +08:00
|
|
|
|
}
|
2025-09-09 20:25:48 +08:00
|
|
|
|
return examples.map((text, index) => ({
|
|
|
|
|
|
id: index + 1,
|
|
|
|
|
|
text: text
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}))
|
|
|
|
|
|
})
|
2025-09-09 20:25:48 +08:00
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// Keep per-thread streaming scratch data in a consistent shape.
|
|
|
|
|
|
const createOnGoingConvState = () => ({
|
|
|
|
|
|
msgChunks: {},
|
|
|
|
|
|
currentRequestKey: null,
|
|
|
|
|
|
currentAssistantKey: null,
|
|
|
|
|
|
toolCallBuffers: {}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
// 业务状态(保留在组件本地)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const chatState = reactive({
|
|
|
|
|
|
currentThreadId: null,
|
|
|
|
|
|
// 以threadId为键的线程状态
|
|
|
|
|
|
threadStates: {}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 组件级别的线程和消息状态
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threads = ref([])
|
|
|
|
|
|
const threadMessages = ref({})
|
2026-03-06 10:14:43 +08:00
|
|
|
|
const hasMoreChats = ref(true) // 是否还有更多对话可加载
|
|
|
|
|
|
const isLoadingMoreChats = ref(false) // 加载更多对话中
|
2026-03-04 08:53:50 +08:00
|
|
|
|
const threadFilesMap = ref({})
|
|
|
|
|
|
const threadAttachmentsMap = ref({})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
// 本地 UI 状态(仅在本组件使用)
|
|
|
|
|
|
const localUIState = reactive({
|
2026-01-15 06:01:34 +08:00
|
|
|
|
isInitialRender: true
|
|
|
|
|
|
})
|
2025-08-25 13:57:47 +08:00
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
// Agent Panel State
|
|
|
|
|
|
const isAgentPanelOpen = ref(false)
|
2026-02-02 21:44:10 +08:00
|
|
|
|
const isResizing = ref(false)
|
|
|
|
|
|
const panelRatio = ref(0.4) // 面板宽度比例 (0-1)
|
|
|
|
|
|
const panelWrapperRef = ref(null) // 直接操作 DOM
|
|
|
|
|
|
const minPanelRatio = 0.3 // 最小比例 30%
|
|
|
|
|
|
const maxPanelRatio = 0.6 // 最大比例 60%
|
|
|
|
|
|
let panelContainerWidth = 0
|
2025-11-14 12:50:32 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== COMPUTED PROPERTIES ====================
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const currentAgentId = computed(() => {
|
|
|
|
|
|
if (props.singleMode) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return props.agentId || defaultAgentId.value
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} else {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return selectedAgentId.value
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-11-07 12:28:58 +08:00
|
|
|
|
const currentAgentName = computed(() => {
|
2026-01-24 15:24:25 +08:00
|
|
|
|
const agent = currentAgent.value
|
|
|
|
|
|
return agent ? agent.name : '智能体'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-09-09 20:25:48 +08:00
|
|
|
|
|
2025-11-07 12:38:29 +08:00
|
|
|
|
const currentAgent = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!currentAgentId.value || !agents.value || !agents.value.length) return null
|
|
|
|
|
|
return agents.value.find((a) => a.id === currentAgentId.value) || null
|
|
|
|
|
|
})
|
|
|
|
|
|
const chatsList = computed(() => threads.value || [])
|
|
|
|
|
|
const currentChatId = computed(() => chatState.currentThreadId)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const currentThread = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!currentChatId.value) return null
|
|
|
|
|
|
return threads.value.find((thread) => thread.id === currentChatId.value) || null
|
|
|
|
|
|
})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-11-08 10:51:30 +08:00
|
|
|
|
// 检查当前智能体是否支持文件上传
|
|
|
|
|
|
const supportsFileUpload = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!currentAgent.value) return false
|
|
|
|
|
|
const capabilities = currentAgent.value.capabilities || []
|
|
|
|
|
|
return capabilities.includes('file_upload')
|
|
|
|
|
|
})
|
2025-11-14 12:50:32 +08:00
|
|
|
|
const supportsTodo = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!currentAgent.value) return false
|
|
|
|
|
|
const capabilities = currentAgent.value.capabilities || []
|
|
|
|
|
|
return capabilities.includes('todo')
|
|
|
|
|
|
})
|
2025-11-14 12:50:32 +08:00
|
|
|
|
|
|
|
|
|
|
const supportsFiles = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!currentAgent.value) return false
|
|
|
|
|
|
const capabilities = currentAgent.value.capabilities || []
|
|
|
|
|
|
return capabilities.includes('files')
|
|
|
|
|
|
})
|
2025-11-14 12:50:32 +08:00
|
|
|
|
|
2026-02-24 18:03:47 +08:00
|
|
|
|
const currentCapabilities = computed(() => {
|
|
|
|
|
|
return currentAgent.value?.capabilities || []
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-11-14 12:50:32 +08:00
|
|
|
|
// AgentState 相关计算属性
|
|
|
|
|
|
const currentAgentState = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return currentChatId.value ? getThreadState(currentChatId.value)?.agentState || null : null
|
|
|
|
|
|
})
|
2026-03-04 08:53:50 +08:00
|
|
|
|
const currentThreadFiles = computed(() => {
|
|
|
|
|
|
if (!currentChatId.value) return []
|
|
|
|
|
|
return threadFilesMap.value[currentChatId.value] || []
|
|
|
|
|
|
})
|
|
|
|
|
|
const currentThreadAttachments = computed(() => {
|
|
|
|
|
|
if (!currentChatId.value) return []
|
|
|
|
|
|
return threadAttachmentsMap.value[currentChatId.value] || []
|
|
|
|
|
|
})
|
2025-11-17 12:01:59 +08:00
|
|
|
|
|
2025-11-14 12:50:32 +08:00
|
|
|
|
const hasAgentStateContent = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const s = currentAgentState.value
|
2026-03-04 08:53:50 +08:00
|
|
|
|
if (!s && currentThreadFiles.value.length === 0) return false
|
|
|
|
|
|
const todoCount = Array.isArray(s?.todos) ? s.todos.length : 0
|
|
|
|
|
|
const fileCount = currentThreadFiles.value.filter((item) => item?.is_dir !== true).length
|
2026-02-13 22:16:11 +08:00
|
|
|
|
return todoCount > 0 || fileCount > 0
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-11-14 12:50:32 +08:00
|
|
|
|
|
2026-03-09 01:23:15 +08:00
|
|
|
|
// 监听 hasAgentStateContent 从 false → true 时,自动展开面板
|
|
|
|
|
|
watch(hasAgentStateContent, (newVal, oldVal) => {
|
|
|
|
|
|
if (newVal && !oldVal) {
|
|
|
|
|
|
// 从无状态变为有状态时,自动展开面板
|
|
|
|
|
|
isAgentPanelOpen.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-02-04 17:05:26 +08:00
|
|
|
|
const mentionConfig = computed(() => {
|
2026-03-04 08:53:50 +08:00
|
|
|
|
const fileMap = new Map()
|
|
|
|
|
|
currentThreadFiles.value
|
|
|
|
|
|
.filter((item) => item && item.is_dir !== true && typeof item.path === 'string')
|
|
|
|
|
|
.forEach((item) => {
|
|
|
|
|
|
fileMap.set(item.path, {
|
|
|
|
|
|
path: item.path,
|
|
|
|
|
|
size: item.size,
|
|
|
|
|
|
modified_at: item.modified_at,
|
|
|
|
|
|
artifact_url: item.artifact_url
|
2026-02-13 22:16:11 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
2026-03-04 08:53:50 +08:00
|
|
|
|
|
|
|
|
|
|
currentThreadAttachments.value.forEach((item) => {
|
2026-03-05 22:50:38 +08:00
|
|
|
|
const candidates = [[item?.path, item?.artifact_url]]
|
2026-03-04 08:53:50 +08:00
|
|
|
|
candidates.forEach(([path, artifactUrl]) => {
|
|
|
|
|
|
if (typeof path !== 'string' || !path) return
|
|
|
|
|
|
if (!fileMap.has(path)) {
|
|
|
|
|
|
fileMap.set(path, {
|
|
|
|
|
|
path,
|
|
|
|
|
|
artifact_url: artifactUrl || null
|
2026-02-04 17:05:26 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2026-03-04 08:53:50 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const files = Array.from(fileMap.values())
|
2026-02-04 17:05:26 +08:00
|
|
|
|
|
|
|
|
|
|
// Filter KBs and MCPs based on agent config
|
|
|
|
|
|
const configItems = configurableItems.value || {}
|
|
|
|
|
|
const currentConfig = agentConfig.value || {}
|
|
|
|
|
|
const allowedKbNames = new Set()
|
|
|
|
|
|
const allowedMcpNames = new Set()
|
|
|
|
|
|
|
|
|
|
|
|
Object.entries(configItems).forEach(([key, item]) => {
|
|
|
|
|
|
const kind = item?.template_metadata?.kind
|
|
|
|
|
|
const val = currentConfig[key]
|
|
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(val)) {
|
|
|
|
|
|
if (kind === 'knowledges') {
|
|
|
|
|
|
val.forEach((v) => allowedKbNames.add(v))
|
|
|
|
|
|
} else if (kind === 'mcps') {
|
|
|
|
|
|
val.forEach((v) => allowedMcpNames.add(v))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const knowledgeBases = availableKnowledgeBases.value.filter((kb) => allowedKbNames.has(kb.name))
|
|
|
|
|
|
const mcps = availableMcps.value.filter((mcp) => allowedMcpNames.has(mcp.name))
|
|
|
|
|
|
|
|
|
|
|
|
if (!files.length && !knowledgeBases.length && !mcps.length) return null
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
files,
|
|
|
|
|
|
knowledgeBases,
|
|
|
|
|
|
mcps
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const currentThreadMessages = computed(() => threadMessages.value[currentChatId.value] || [])
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// 计算是否显示Refs组件的条件
|
|
|
|
|
|
const shouldShowRefs = computed(() => {
|
|
|
|
|
|
return (conv) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return (
|
|
|
|
|
|
getLastMessage(conv) &&
|
|
|
|
|
|
conv.status !== 'streaming' &&
|
|
|
|
|
|
!approvalState.showModal &&
|
|
|
|
|
|
!(
|
|
|
|
|
|
approvalState.threadId &&
|
|
|
|
|
|
chatState.currentThreadId === approvalState.threadId &&
|
|
|
|
|
|
isProcessing.value
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 当前线程状态的computed属性
|
|
|
|
|
|
const currentThreadState = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return getThreadState(currentChatId.value)
|
|
|
|
|
|
})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
const onGoingConvMessages = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threadState = currentThreadState.value
|
|
|
|
|
|
if (!threadState || !threadState.onGoingConv) return []
|
2025-09-03 03:00:25 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const msgs = Object.values(threadState.onGoingConv.msgChunks).map(
|
|
|
|
|
|
MessageProcessor.mergeMessageChunk
|
|
|
|
|
|
)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
return msgs.length > 0
|
2026-01-15 06:01:34 +08:00
|
|
|
|
? MessageProcessor.convertToolResultToMessages(msgs).filter((msg) => msg.type !== 'tool')
|
|
|
|
|
|
: []
|
|
|
|
|
|
})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-12-19 14:41:23 +08:00
|
|
|
|
const historyConversations = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return MessageProcessor.convertServerHistoryToMessages(currentThreadMessages.value)
|
|
|
|
|
|
})
|
2025-12-19 14:41:23 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const conversations = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const historyConvs = historyConversations.value
|
2025-10-15 02:37:42 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果有进行中的消息且线程状态显示正在流式处理,添加进行中的对话
|
2025-12-19 02:22:29 +08:00
|
|
|
|
if (onGoingConvMessages.value.length > 0) {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const onGoingConv = {
|
|
|
|
|
|
messages: onGoingConvMessages.value,
|
|
|
|
|
|
status: 'streaming'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
return [...historyConvs, onGoingConv]
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return historyConvs
|
|
|
|
|
|
})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const isLoadingMessages = computed(() => chatUIStore.isLoadingMessages)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const isStreaming = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threadState = currentThreadState.value
|
|
|
|
|
|
return threadState ? threadState.isStreaming : false
|
|
|
|
|
|
})
|
|
|
|
|
|
const isProcessing = computed(() => isStreaming.value)
|
2025-08-10 21:58:41 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== SCROLL & RESIZE HANDLING ====================
|
2026-01-24 15:24:25 +08:00
|
|
|
|
// Update scroll controller to target .chat-main
|
|
|
|
|
|
const scrollController = new ScrollController('.chat-main')
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
nextTick(() => {
|
2026-01-24 15:24:25 +08:00
|
|
|
|
// Update event listener to target .chat-main
|
|
|
|
|
|
const chatMainContainer = document.querySelector('.chat-main')
|
|
|
|
|
|
if (chatMainContainer) {
|
|
|
|
|
|
chatMainContainer.addEventListener('scroll', scrollController.handleScroll, { passive: true })
|
2025-06-24 00:15:51 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
localUIState.isInitialRender = false
|
|
|
|
|
|
}, 300)
|
|
|
|
|
|
})
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
2026-02-25 16:26:09 +08:00
|
|
|
|
stopTypingRenderLoop()
|
|
|
|
|
|
typingChunkQueue.length = 0
|
|
|
|
|
|
pendingTypingChars = 0
|
2026-01-15 06:01:34 +08:00
|
|
|
|
scrollController.cleanup()
|
|
|
|
|
|
// 清理所有线程状态
|
|
|
|
|
|
resetOnGoingConv()
|
|
|
|
|
|
})
|
2025-08-25 01:46:31 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// ==================== THREAD STATE MANAGEMENT ====================
|
|
|
|
|
|
// 获取指定线程的状态,如果不存在则创建
|
|
|
|
|
|
const getThreadState = (threadId) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!threadId) return null
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!chatState.threadStates[threadId]) {
|
|
|
|
|
|
chatState.threadStates[threadId] = {
|
|
|
|
|
|
isStreaming: false,
|
|
|
|
|
|
streamAbortController: null,
|
2026-02-25 16:26:09 +08:00
|
|
|
|
runStreamAbortController: null,
|
|
|
|
|
|
activeRunId: null,
|
|
|
|
|
|
runLastSeq: '0',
|
|
|
|
|
|
lastRetryableJobTry: null,
|
2025-11-14 12:50:32 +08:00
|
|
|
|
onGoingConv: createOnGoingConvState(),
|
2026-01-15 06:01:34 +08:00
|
|
|
|
agentState: null // 添加 agentState 字段
|
|
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return chatState.threadStates[threadId]
|
|
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 清理指定线程的状态
|
|
|
|
|
|
const cleanupThreadState = (threadId) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!threadId) return
|
|
|
|
|
|
const threadState = chatState.threadStates[threadId]
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (threadState) {
|
2026-02-25 16:26:09 +08:00
|
|
|
|
clearTypingQueueForThread(threadId)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (threadState.streamAbortController) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadState.streamAbortController.abort()
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-02-25 16:26:09 +08:00
|
|
|
|
if (threadState.runStreamAbortController) {
|
|
|
|
|
|
threadState.runStreamAbortController.abort()
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
delete chatState.threadStates[threadId]
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-03-04 08:53:50 +08:00
|
|
|
|
delete threadFilesMap.value[threadId]
|
|
|
|
|
|
delete threadAttachmentsMap.value[threadId]
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// ==================== STREAM HANDLING LOGIC ====================
|
2025-12-19 02:22:29 +08:00
|
|
|
|
const resetOnGoingConv = (threadId = null) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const targetThreadId = threadId || currentChatId.value
|
2025-12-19 02:22:29 +08:00
|
|
|
|
|
|
|
|
|
|
if (targetThreadId) {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 清理指定线程的状态
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threadState = getThreadState(targetThreadId)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (threadState) {
|
2026-02-25 16:26:09 +08:00
|
|
|
|
clearTypingQueueForThread(targetThreadId)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (threadState.streamAbortController) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadState.streamAbortController.abort()
|
|
|
|
|
|
threadState.streamAbortController = null
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-02-25 16:26:09 +08:00
|
|
|
|
if (threadState.runStreamAbortController) {
|
|
|
|
|
|
threadState.runStreamAbortController.abort()
|
|
|
|
|
|
threadState.runStreamAbortController = null
|
|
|
|
|
|
}
|
2025-12-19 02:22:29 +08:00
|
|
|
|
|
|
|
|
|
|
// 直接重置对话状态
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadState.onGoingConv = createOnGoingConvState()
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-12-19 02:22:29 +08:00
|
|
|
|
// 如果没有当前线程,清理所有线程状态
|
2026-01-15 06:01:34 +08:00
|
|
|
|
Object.keys(chatState.threadStates).forEach((tid) => {
|
|
|
|
|
|
cleanupThreadState(tid)
|
|
|
|
|
|
})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// ==================== 线程管理方法 ====================
|
|
|
|
|
|
// 获取当前智能体的线程列表
|
|
|
|
|
|
const fetchThreads = async (agentId = null) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const targetAgentId = agentId || currentAgentId.value
|
|
|
|
|
|
if (!targetAgentId) return
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatUIStore.isLoadingThreads = true
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
2026-03-06 10:14:43 +08:00
|
|
|
|
const fetchedThreads = await threadApi.getThreads(targetAgentId, 100, 0)
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threads.value = fetchedThreads || []
|
2026-03-06 10:14:43 +08:00
|
|
|
|
// 如果返回的数量小于limit,说明没有更多了
|
|
|
|
|
|
hasMoreChats.value = fetchedThreads && fetchedThreads.length >= 100
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('Failed to fetch threads:', error)
|
|
|
|
|
|
handleChatError(error, 'fetch')
|
|
|
|
|
|
throw error
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} finally {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatUIStore.isLoadingThreads = false
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-03-06 10:14:43 +08:00
|
|
|
|
// 加载更多对话
|
|
|
|
|
|
const loadMoreChats = async () => {
|
|
|
|
|
|
if (isLoadingMoreChats.value || !hasMoreChats.value) return
|
|
|
|
|
|
|
|
|
|
|
|
const targetAgentId = currentAgentId.value
|
|
|
|
|
|
if (!targetAgentId) return
|
|
|
|
|
|
|
|
|
|
|
|
isLoadingMoreChats.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const offset = threads.value.length
|
|
|
|
|
|
const fetchedThreads = await threadApi.getThreads(targetAgentId, 100, offset)
|
|
|
|
|
|
if (fetchedThreads && fetchedThreads.length > 0) {
|
2026-03-06 20:29:58 +08:00
|
|
|
|
// 去除重复的置顶对话(后端每次都返回所有置顶对话)
|
|
|
|
|
|
const existingIds = new Set(threads.value.map((t) => t.id))
|
|
|
|
|
|
const newThreads = fetchedThreads.filter((t) => !existingIds.has(t.id))
|
|
|
|
|
|
|
|
|
|
|
|
threads.value = [...threads.value, ...newThreads]
|
|
|
|
|
|
hasMoreChats.value = newThreads.length >= 100
|
2026-03-06 10:14:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
hasMoreChats.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to load more chats:', error)
|
|
|
|
|
|
handleChatError(error, 'fetch')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
isLoadingMoreChats.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 创建新线程
|
|
|
|
|
|
const createThread = async (agentId, title = '新的对话') => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!agentId) return null
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.isCreatingThread = true
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const thread = await threadApi.createThread(agentId, title)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (thread) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threads.value.unshift(thread)
|
|
|
|
|
|
threadMessages.value[thread.id] = []
|
2026-03-04 08:53:50 +08:00
|
|
|
|
threadFilesMap.value[thread.id] = []
|
|
|
|
|
|
threadAttachmentsMap.value[thread.id] = []
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return thread
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('Failed to create thread:', error)
|
|
|
|
|
|
handleChatError(error, 'create')
|
|
|
|
|
|
throw error
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} finally {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.isCreatingThread = false
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 删除线程
|
|
|
|
|
|
const deleteThread = async (threadId) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!threadId) return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.isDeletingThread = true
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await threadApi.deleteThread(threadId)
|
|
|
|
|
|
threads.value = threads.value.filter((thread) => thread.id !== threadId)
|
|
|
|
|
|
delete threadMessages.value[threadId]
|
2026-03-04 08:53:50 +08:00
|
|
|
|
delete threadFilesMap.value[threadId]
|
|
|
|
|
|
delete threadAttachmentsMap.value[threadId]
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
if (chatState.currentThreadId === threadId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.currentThreadId = null
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('Failed to delete thread:', error)
|
|
|
|
|
|
handleChatError(error, 'delete')
|
|
|
|
|
|
throw error
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} finally {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.isDeletingThread = false
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 更新线程标题
|
2026-03-06 20:29:58 +08:00
|
|
|
|
const updateThread = async (threadId, title, is_pinned) => {
|
|
|
|
|
|
if (!threadId) return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-03-06 20:29:58 +08:00
|
|
|
|
if (title) {
|
|
|
|
|
|
const normalizedTitle = String(title).replace(/\s+/g, ' ').trim().slice(0, 255)
|
|
|
|
|
|
if (!normalizedTitle) return
|
2026-02-20 23:41:44 +08:00
|
|
|
|
|
2026-03-06 20:29:58 +08:00
|
|
|
|
chatState.isRenamingThread = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await threadApi.updateThread(threadId, normalizedTitle, is_pinned)
|
|
|
|
|
|
const thread = threads.value.find((t) => t.id === threadId)
|
|
|
|
|
|
if (thread) {
|
|
|
|
|
|
thread.title = normalizedTitle
|
|
|
|
|
|
if (is_pinned !== undefined) {
|
|
|
|
|
|
thread.is_pinned = is_pinned
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to update thread:', error)
|
|
|
|
|
|
handleChatError(error, 'update')
|
|
|
|
|
|
throw error
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
chatState.isRenamingThread = false
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (is_pinned !== undefined) {
|
|
|
|
|
|
// 只更新置顶状态
|
|
|
|
|
|
try {
|
|
|
|
|
|
await threadApi.updateThread(threadId, null, is_pinned)
|
|
|
|
|
|
const thread = threads.value.find((t) => t.id === threadId)
|
|
|
|
|
|
if (thread) {
|
|
|
|
|
|
thread.is_pinned = is_pinned
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to update thread pin status:', error)
|
|
|
|
|
|
handleChatError(error, 'update')
|
|
|
|
|
|
throw error
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取线程消息
|
2025-11-12 11:00:39 +08:00
|
|
|
|
const fetchThreadMessages = async ({ agentId, threadId, delay = 0 }) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!threadId || !agentId) return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-11-12 11:00:39 +08:00
|
|
|
|
// 如果指定了延迟,等待指定时间(用于确保后端数据库事务提交)
|
|
|
|
|
|
if (delay > 0) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, delay))
|
2025-11-12 11:00:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const response = await agentApi.getAgentHistory(agentId, threadId)
|
|
|
|
|
|
threadMessages.value[threadId] = response.history || []
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'load')
|
|
|
|
|
|
throw error
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-03-04 08:53:50 +08:00
|
|
|
|
const fetchThreadFiles = async (threadId) => {
|
|
|
|
|
|
if (!threadId) return
|
|
|
|
|
|
const queue = ['/mnt/user-data']
|
|
|
|
|
|
const visited = new Set()
|
|
|
|
|
|
const entries = []
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
while (queue.length > 0) {
|
|
|
|
|
|
const currentPath = queue.shift()
|
|
|
|
|
|
if (!currentPath || visited.has(currentPath)) continue
|
|
|
|
|
|
visited.add(currentPath)
|
|
|
|
|
|
|
|
|
|
|
|
const response = await threadApi.listThreadFiles(threadId, currentPath)
|
|
|
|
|
|
const files = Array.isArray(response?.files) ? response.files : []
|
|
|
|
|
|
files.forEach((item) => {
|
|
|
|
|
|
if (!item || typeof item.path !== 'string') return
|
|
|
|
|
|
entries.push(item)
|
|
|
|
|
|
if (item.is_dir === true) {
|
|
|
|
|
|
queue.push(item.path)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
threadFilesMap.value[threadId] = entries
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.warn('Failed to fetch thread files:', error)
|
|
|
|
|
|
threadFilesMap.value[threadId] = []
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fetchThreadAttachments = async (threadId) => {
|
|
|
|
|
|
if (!threadId) return
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await threadApi.getThreadAttachments(threadId)
|
|
|
|
|
|
threadAttachmentsMap.value[threadId] = Array.isArray(response?.attachments)
|
|
|
|
|
|
? response.attachments
|
|
|
|
|
|
: []
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.warn('Failed to fetch thread attachments:', error)
|
|
|
|
|
|
threadAttachmentsMap.value[threadId] = []
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const refreshThreadFilesAndAttachments = async (threadId) => {
|
|
|
|
|
|
if (!threadId) return
|
|
|
|
|
|
await Promise.all([fetchThreadFiles(threadId), fetchThreadAttachments(threadId)])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-17 12:01:59 +08:00
|
|
|
|
const fetchAgentState = async (agentId, threadId) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!agentId || !threadId) return
|
2025-11-17 12:01:59 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const res = await agentApi.getAgentState(agentId, threadId)
|
2026-02-13 22:16:11 +08:00
|
|
|
|
const targetChatId = currentChatId.value || threadId
|
|
|
|
|
|
const ts = getThreadState(targetChatId)
|
|
|
|
|
|
if (ts) {
|
|
|
|
|
|
ts.agentState = res.agent_state || null
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const newTs = getThreadState(threadId)
|
|
|
|
|
|
if (newTs) newTs.agentState = res.agent_state || null
|
|
|
|
|
|
}
|
2026-02-24 14:22:11 +08:00
|
|
|
|
} catch {
|
|
|
|
|
|
// 忽略状态拉取失败,不阻塞主流程
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-17 12:01:59 +08:00
|
|
|
|
|
2026-02-25 16:26:09 +08:00
|
|
|
|
const RUN_TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled', 'interrupted'])
|
|
|
|
|
|
|
|
|
|
|
|
const getActiveRunStorageKey = (threadId) => `active_run:${threadId}`
|
|
|
|
|
|
|
|
|
|
|
|
const normalizeRunSeq = (value) => {
|
|
|
|
|
|
if (value === undefined || value === null) return '0'
|
|
|
|
|
|
const text = String(value).trim()
|
|
|
|
|
|
return text || '0'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const parseRunSeq = (value) => {
|
|
|
|
|
|
const text = normalizeRunSeq(value)
|
|
|
|
|
|
if (text.includes('-')) {
|
|
|
|
|
|
const [majorRaw, minorRaw] = text.split('-', 2)
|
|
|
|
|
|
let major = 0n
|
|
|
|
|
|
let minor = 0n
|
|
|
|
|
|
try {
|
|
|
|
|
|
major = BigInt(majorRaw || '0')
|
|
|
|
|
|
minor = BigInt(minorRaw || '0')
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return { kind: 'legacy', value: 0 }
|
|
|
|
|
|
}
|
|
|
|
|
|
return { kind: 'stream', major, minor }
|
|
|
|
|
|
}
|
|
|
|
|
|
const numberValue = Number.parseInt(text, 10)
|
|
|
|
|
|
if (!Number.isNaN(numberValue)) {
|
|
|
|
|
|
return { kind: 'legacy', value: numberValue }
|
|
|
|
|
|
}
|
|
|
|
|
|
return { kind: 'legacy', value: 0 }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const compareRunSeq = (incoming, current) => {
|
|
|
|
|
|
const left = parseRunSeq(incoming)
|
|
|
|
|
|
const right = parseRunSeq(current)
|
|
|
|
|
|
|
|
|
|
|
|
if (left.kind === 'stream' && right.kind === 'stream') {
|
|
|
|
|
|
if (left.major > right.major) return 1
|
|
|
|
|
|
if (left.major < right.major) return -1
|
|
|
|
|
|
if (left.minor > right.minor) return 1
|
|
|
|
|
|
if (left.minor < right.minor) return -1
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (left.kind === 'legacy' && right.kind === 'legacy') {
|
|
|
|
|
|
return left.value - right.value
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (left.kind === 'stream' && right.kind === 'legacy') return 1
|
|
|
|
|
|
return -1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const saveActiveRunSnapshot = (threadId, runId, lastSeq = '0') => {
|
|
|
|
|
|
if (!threadId || !runId) return
|
|
|
|
|
|
localStorage.setItem(
|
|
|
|
|
|
getActiveRunStorageKey(threadId),
|
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
|
run_id: runId,
|
|
|
|
|
|
last_seq: normalizeRunSeq(lastSeq),
|
|
|
|
|
|
created_at: Date.now(),
|
|
|
|
|
|
client_id: ACTIVE_RUN_CLIENT_ID
|
|
|
|
|
|
})
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const loadActiveRunSnapshot = (threadId) => {
|
|
|
|
|
|
if (!threadId) return null
|
|
|
|
|
|
try {
|
|
|
|
|
|
const raw = localStorage.getItem(getActiveRunStorageKey(threadId))
|
|
|
|
|
|
return raw ? JSON.parse(raw) : null
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return null
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const clearActiveRunSnapshot = (threadId) => {
|
|
|
|
|
|
if (!threadId) return
|
|
|
|
|
|
localStorage.removeItem(getActiveRunStorageKey(threadId))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const splitChars = (text) => {
|
|
|
|
|
|
if (typeof text !== 'string' || !text) return []
|
|
|
|
|
|
return Array.from(text)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const calcTypingCps = () => {
|
|
|
|
|
|
if (pendingTypingChars <= 0) return MIN_TYPING_CPS
|
|
|
|
|
|
const ratio = Math.min(1, pendingTypingChars / TYPING_BACKLOG_HIGH_WATERMARK)
|
|
|
|
|
|
return Math.round(MIN_TYPING_CPS + ratio * (MAX_TYPING_CPS - MIN_TYPING_CPS))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const scheduleTypingRender = () => {
|
|
|
|
|
|
if (typingAnimationFrameId !== null) return
|
|
|
|
|
|
if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') {
|
|
|
|
|
|
typingAnimationFrameId = window.requestAnimationFrame(drainTypingQueue)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
typingAnimationFrameId = setTimeout(() => {
|
|
|
|
|
|
typingAnimationFrameId = null
|
|
|
|
|
|
drainTypingQueue(Date.now())
|
|
|
|
|
|
}, 16)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const stopTypingRenderLoop = () => {
|
|
|
|
|
|
if (typingAnimationFrameId === null) return
|
|
|
|
|
|
if (typeof window !== 'undefined' && typeof window.cancelAnimationFrame === 'function') {
|
|
|
|
|
|
window.cancelAnimationFrame(typingAnimationFrameId)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
clearTimeout(typingAnimationFrameId)
|
|
|
|
|
|
}
|
|
|
|
|
|
typingAnimationFrameId = null
|
|
|
|
|
|
typingLastFrameTs = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const enqueueLoadingChunkForTyping = (threadId, chunk) => {
|
|
|
|
|
|
if (!threadId || !chunk) return
|
|
|
|
|
|
if (chunk.status !== 'loading') {
|
|
|
|
|
|
typingChunkQueue.push({ threadId, chunk, isChar: false })
|
|
|
|
|
|
scheduleTypingRender()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const msg = chunk.msg || {}
|
2026-02-25 19:09:04 +08:00
|
|
|
|
const msgType = String(msg.type || '').toLowerCase()
|
|
|
|
|
|
const isToolMessage = msgType === 'tool' || msgType.includes('tool')
|
|
|
|
|
|
const streamText = typeof chunk.response === 'string' ? chunk.response : ''
|
|
|
|
|
|
const contentChars = !isToolMessage ? splitChars(streamText) : []
|
2026-02-25 16:26:09 +08:00
|
|
|
|
if (contentChars.length === 0) {
|
|
|
|
|
|
typingChunkQueue.push({ threadId, chunk, isChar: false })
|
|
|
|
|
|
scheduleTypingRender()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const char of contentChars) {
|
|
|
|
|
|
typingChunkQueue.push({
|
|
|
|
|
|
threadId,
|
|
|
|
|
|
isChar: true,
|
|
|
|
|
|
chunk: {
|
|
|
|
|
|
...chunk,
|
2026-02-25 19:09:04 +08:00
|
|
|
|
response: char,
|
2026-02-25 16:26:09 +08:00
|
|
|
|
msg: {
|
|
|
|
|
|
...msg,
|
|
|
|
|
|
content: char
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
pendingTypingChars += contentChars.length
|
|
|
|
|
|
scheduleTypingRender()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将队列按 threadId 分区,对匹配项执行回调,返回移除的字符数
|
|
|
|
|
|
const partitionTypingQueue = (threadId, onMatch = null) => {
|
|
|
|
|
|
const remaining = []
|
|
|
|
|
|
let charCount = 0
|
|
|
|
|
|
for (const item of typingChunkQueue) {
|
|
|
|
|
|
if (item.threadId === threadId) {
|
|
|
|
|
|
if (onMatch) onMatch(item)
|
|
|
|
|
|
if (item.isChar) charCount += 1
|
|
|
|
|
|
} else {
|
|
|
|
|
|
remaining.push(item)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
typingChunkQueue.length = 0
|
|
|
|
|
|
typingChunkQueue.push(...remaining)
|
|
|
|
|
|
pendingTypingChars = Math.max(0, pendingTypingChars - charCount)
|
|
|
|
|
|
typingChunkQueue.length === 0 ? stopTypingRenderLoop() : scheduleTypingRender()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const clearTypingQueueForThread = (threadId) => {
|
|
|
|
|
|
if (!threadId || typingChunkQueue.length === 0) return
|
|
|
|
|
|
partitionTypingQueue(threadId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const flushTypingQueueForThread = (threadId) => {
|
|
|
|
|
|
if (!threadId || typingChunkQueue.length === 0) return
|
|
|
|
|
|
partitionTypingQueue(threadId, (item) => handleStreamChunk(item.chunk, threadId))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function drainTypingQueue(frameTs = Date.now()) {
|
|
|
|
|
|
typingAnimationFrameId = null
|
|
|
|
|
|
if (typingChunkQueue.length === 0) {
|
|
|
|
|
|
typingLastFrameTs = 0
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!typingLastFrameTs) {
|
|
|
|
|
|
typingLastFrameTs = frameTs
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const elapsedSeconds = Math.max(0.001, (frameTs - typingLastFrameTs) / 1000)
|
|
|
|
|
|
typingLastFrameTs = frameTs
|
|
|
|
|
|
const cps = calcTypingCps()
|
|
|
|
|
|
let budget = Math.max(1, Math.floor(elapsedSeconds * cps))
|
|
|
|
|
|
|
|
|
|
|
|
while (budget > 0 && typingChunkQueue.length > 0) {
|
|
|
|
|
|
const item = typingChunkQueue.shift()
|
|
|
|
|
|
if (!item) break
|
|
|
|
|
|
handleStreamChunk(item.chunk, item.threadId)
|
|
|
|
|
|
if (item.isChar) {
|
|
|
|
|
|
pendingTypingChars = Math.max(0, pendingTypingChars - 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
budget -= 1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (typingChunkQueue.length > 0) {
|
|
|
|
|
|
scheduleTypingRender()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
typingLastFrameTs = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const processRunSseResponse = async (response, onEvent) => {
|
|
|
|
|
|
if (!response || !response.body) return
|
|
|
|
|
|
const reader = response.body.getReader()
|
|
|
|
|
|
const decoder = new TextDecoder()
|
|
|
|
|
|
let buffer = ''
|
|
|
|
|
|
let eventType = 'message'
|
|
|
|
|
|
let dataLines = []
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
const { done, value } = await reader.read()
|
|
|
|
|
|
if (done) break
|
|
|
|
|
|
buffer += decoder.decode(value, { stream: true })
|
|
|
|
|
|
const lines = buffer.split('\n')
|
|
|
|
|
|
buffer = lines.pop() || ''
|
|
|
|
|
|
|
|
|
|
|
|
for (const rawLine of lines) {
|
|
|
|
|
|
const line = rawLine.replace(/\r$/, '')
|
|
|
|
|
|
if (!line) {
|
|
|
|
|
|
if (dataLines.length > 0) {
|
|
|
|
|
|
const dataText = dataLines.join('\n')
|
|
|
|
|
|
try {
|
|
|
|
|
|
const parsed = JSON.parse(dataText)
|
|
|
|
|
|
onEvent(eventType, parsed)
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('Failed to parse run SSE data:', e, dataText)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
eventType = 'message'
|
|
|
|
|
|
dataLines = []
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if (line.startsWith('event:')) {
|
|
|
|
|
|
eventType = line.slice(6).trim() || 'message'
|
|
|
|
|
|
} else if (line.startsWith('data:')) {
|
|
|
|
|
|
dataLines.push(line.slice(5).trim())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (dataLines.length > 0) {
|
|
|
|
|
|
const dataText = dataLines.join('\n')
|
|
|
|
|
|
try {
|
|
|
|
|
|
const parsed = JSON.parse(dataText)
|
|
|
|
|
|
onEvent(eventType, parsed)
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('Failed to parse trailing run SSE data:', e, dataText)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
try {
|
|
|
|
|
|
reader.releaseLock()
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// ignore
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const stopRunStreamSubscription = (threadId) => {
|
|
|
|
|
|
const ts = getThreadState(threadId)
|
|
|
|
|
|
if (!ts) return
|
|
|
|
|
|
if (ts.runStreamAbortController) {
|
|
|
|
|
|
ts.runStreamAbortController.abort()
|
|
|
|
|
|
ts.runStreamAbortController = null
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const startRunStream = async (threadId, runId, afterSeq = '0') => {
|
|
|
|
|
|
if (!threadId || !runId || !useRunsApi) return
|
|
|
|
|
|
const ts = getThreadState(threadId)
|
|
|
|
|
|
if (!ts) return
|
|
|
|
|
|
|
|
|
|
|
|
stopRunStreamSubscription(threadId)
|
|
|
|
|
|
const runController = new AbortController()
|
|
|
|
|
|
ts.runStreamAbortController = runController
|
|
|
|
|
|
ts.activeRunId = runId
|
|
|
|
|
|
ts.runLastSeq = normalizeRunSeq(afterSeq)
|
|
|
|
|
|
ts.lastRetryableJobTry = null
|
|
|
|
|
|
ts.isStreaming = true
|
|
|
|
|
|
saveActiveRunSnapshot(threadId, runId, ts.runLastSeq)
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await agentApi.streamAgentRunEvents(runId, ts.runLastSeq, {
|
|
|
|
|
|
signal: runController.signal
|
|
|
|
|
|
})
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
throw new Error(`SSE response not ok: ${response.status}`)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await processRunSseResponse(response, (event, data) => {
|
|
|
|
|
|
if (!data || ts.activeRunId !== runId) return
|
|
|
|
|
|
|
|
|
|
|
|
if (data.seq !== undefined && data.seq !== null) {
|
|
|
|
|
|
const incomingSeq = normalizeRunSeq(data.seq)
|
|
|
|
|
|
if (compareRunSeq(incomingSeq, ts.runLastSeq) <= 0) return
|
|
|
|
|
|
ts.runLastSeq = incomingSeq
|
|
|
|
|
|
saveActiveRunSnapshot(threadId, runId, incomingSeq)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (event === 'heartbeat') return
|
|
|
|
|
|
|
|
|
|
|
|
const payload = data.payload || {}
|
|
|
|
|
|
const isRetryableError = event === 'error' && payload?.chunk?.retryable === true
|
|
|
|
|
|
if (isRetryableError) {
|
|
|
|
|
|
const parsedJobTry = Number.parseInt(payload?.chunk?.job_try, 10)
|
|
|
|
|
|
const retryJobTry = Number.isNaN(parsedJobTry) ? null : parsedJobTry
|
|
|
|
|
|
if (retryJobTry !== null && ts.lastRetryableJobTry === retryJobTry) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
ts.lastRetryableJobTry = retryJobTry
|
|
|
|
|
|
console.warn('Run encountered retryable error, waiting for worker retry', {
|
|
|
|
|
|
threadId,
|
|
|
|
|
|
runId,
|
|
|
|
|
|
retryJobTry,
|
|
|
|
|
|
errorType: payload?.chunk?.error_type
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(payload.items)) {
|
|
|
|
|
|
payload.items.forEach((chunk) => {
|
|
|
|
|
|
enqueueLoadingChunkForTyping(threadId, chunk)
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (payload.chunk) {
|
|
|
|
|
|
enqueueLoadingChunkForTyping(threadId, payload.chunk)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (event === 'close') {
|
|
|
|
|
|
flushTypingQueueForThread(threadId)
|
|
|
|
|
|
ts.isStreaming = false
|
|
|
|
|
|
if (RUN_TERMINAL_STATUSES.has(data.status)) {
|
|
|
|
|
|
ts.activeRunId = null
|
|
|
|
|
|
ts.lastRetryableJobTry = null
|
|
|
|
|
|
clearActiveRunSnapshot(threadId)
|
|
|
|
|
|
fetchThreadMessages({ agentId: currentAgentId.value, threadId, delay: 200 }).finally(() => {
|
2026-03-04 08:53:50 +08:00
|
|
|
|
handleAgentStateRefresh(threadId)
|
2026-02-25 16:26:09 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else if (ts.activeRunId === runId) {
|
|
|
|
|
|
window.setTimeout(() => {
|
|
|
|
|
|
if (ts.activeRunId === runId && !ts.runStreamAbortController) {
|
|
|
|
|
|
void startRunStream(threadId, runId, ts.runLastSeq)
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 300)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-07 23:28:25 +08:00
|
|
|
|
if (
|
|
|
|
|
|
event === 'finished' ||
|
|
|
|
|
|
event === 'error' ||
|
|
|
|
|
|
event === 'interrupted' ||
|
|
|
|
|
|
event === 'ask_user_question_required'
|
|
|
|
|
|
) {
|
2026-02-25 16:26:09 +08:00
|
|
|
|
flushTypingQueueForThread(threadId)
|
|
|
|
|
|
ts.isStreaming = false
|
|
|
|
|
|
ts.activeRunId = null
|
|
|
|
|
|
ts.lastRetryableJobTry = null
|
|
|
|
|
|
clearActiveRunSnapshot(threadId)
|
|
|
|
|
|
fetchThreadMessages({ agentId: currentAgentId.value, threadId, delay: 300 }).finally(() => {
|
|
|
|
|
|
resetOnGoingConv(threadId)
|
2026-03-04 08:53:50 +08:00
|
|
|
|
handleAgentStateRefresh(threadId)
|
2026-02-25 16:26:09 +08:00
|
|
|
|
scrollController.scrollToBottom()
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
if (error?.name !== 'AbortError') {
|
|
|
|
|
|
console.error('Run SSE stream error:', error)
|
|
|
|
|
|
handleChatError(error, 'stream')
|
|
|
|
|
|
if (ts.activeRunId === runId) {
|
|
|
|
|
|
window.setTimeout(() => {
|
|
|
|
|
|
if (ts.activeRunId === runId && !ts.runStreamAbortController) {
|
|
|
|
|
|
void startRunStream(threadId, runId, ts.runLastSeq)
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 500)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
if (ts.runStreamAbortController === runController) {
|
|
|
|
|
|
ts.runStreamAbortController = null
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!ts.activeRunId) {
|
|
|
|
|
|
ts.isStreaming = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const resumeActiveRunForThread = async (threadId) => {
|
|
|
|
|
|
if (!useRunsApi || !threadId) return
|
|
|
|
|
|
const ts = getThreadState(threadId)
|
|
|
|
|
|
if (!ts || ts.runStreamAbortController) return
|
|
|
|
|
|
|
|
|
|
|
|
const snapshot = loadActiveRunSnapshot(threadId)
|
|
|
|
|
|
if (snapshot?.run_id) {
|
|
|
|
|
|
if (Date.now() - Number(snapshot.created_at || 0) > ACTIVE_RUN_STORAGE_TTL_MS) {
|
|
|
|
|
|
clearActiveRunSnapshot(threadId)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const runRes = await agentApi.getAgentRun(snapshot.run_id)
|
|
|
|
|
|
const run = runRes?.run
|
|
|
|
|
|
if (run && !RUN_TERMINAL_STATUSES.has(run.status)) {
|
|
|
|
|
|
await startRunStream(threadId, run.id, snapshot.last_seq || '0')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// ignore
|
|
|
|
|
|
}
|
|
|
|
|
|
clearActiveRunSnapshot(threadId)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const active = await agentApi.getThreadActiveRun(threadId)
|
|
|
|
|
|
const run = active?.run
|
|
|
|
|
|
if (run && !RUN_TERMINAL_STATUSES.has(run.status)) {
|
|
|
|
|
|
await startRunStream(threadId, run.id, 0)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('Failed to load active run for thread:', threadId, e)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ts.activeRunId = null
|
|
|
|
|
|
ts.runLastSeq = '0'
|
|
|
|
|
|
ts.isStreaming = false
|
|
|
|
|
|
clearActiveRunSnapshot(threadId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-08 10:51:30 +08:00
|
|
|
|
const ensureActiveThread = async (title = '新的对话') => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (currentChatId.value) return currentChatId.value
|
2025-11-08 10:51:30 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const newThread = await createThread(currentAgentId.value, title || '新的对话')
|
2025-11-08 10:51:30 +08:00
|
|
|
|
if (newThread) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.currentThreadId = newThread.id
|
|
|
|
|
|
return newThread.id
|
2025-11-08 10:51:30 +08:00
|
|
|
|
}
|
2026-02-24 14:22:11 +08:00
|
|
|
|
} catch {
|
2025-11-08 10:51:30 +08:00
|
|
|
|
// createThread 已处理错误提示
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return null
|
|
|
|
|
|
}
|
2025-11-08 10:51:30 +08:00
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// ==================== 审批功能管理 ====================
|
|
|
|
|
|
const { approvalState, handleApproval, processApprovalInStream } = useApproval({
|
|
|
|
|
|
getThreadState,
|
|
|
|
|
|
resetOnGoingConv,
|
|
|
|
|
|
fetchThreadMessages
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2026-02-25 16:26:09 +08:00
|
|
|
|
const { handleAgentResponse, handleStreamChunk } = useAgentStreamHandler({
|
2025-12-19 04:04:48 +08:00
|
|
|
|
getThreadState,
|
|
|
|
|
|
processApprovalInStream,
|
|
|
|
|
|
currentAgentId,
|
|
|
|
|
|
supportsTodo,
|
|
|
|
|
|
supportsFiles
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-12-19 04:04:48 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 发送消息并处理流式响应
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const sendMessage = async ({
|
|
|
|
|
|
agentId,
|
|
|
|
|
|
threadId,
|
|
|
|
|
|
text,
|
|
|
|
|
|
signal = undefined,
|
|
|
|
|
|
imageData = undefined
|
|
|
|
|
|
}) => {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!agentId || !threadId || !text) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const error = new Error('Missing agent, thread, or message text')
|
|
|
|
|
|
handleChatError(error, 'send')
|
|
|
|
|
|
return Promise.reject(error)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是新对话,用消息内容作为标题
|
|
|
|
|
|
if ((threadMessages.value[threadId] || []).length === 0) {
|
2026-02-20 23:41:44 +08:00
|
|
|
|
const autoTitle = text.replace(/\s+/g, ' ').trim().slice(0, 255)
|
|
|
|
|
|
if (autoTitle) {
|
|
|
|
|
|
void updateThread(threadId, autoTitle).catch(() => {})
|
|
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const requestData = {
|
|
|
|
|
|
query: text,
|
|
|
|
|
|
config: {
|
2026-01-22 05:57:13 +08:00
|
|
|
|
thread_id: threadId,
|
|
|
|
|
|
...(selectedAgentConfigId.value ? { agent_config_id: selectedAgentConfigId.value } : {})
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-11-12 14:04:34 +08:00
|
|
|
|
// 如果有图片,添加到请求中
|
|
|
|
|
|
if (imageData && imageData.imageContent) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
requestData.image_content = imageData.imageContent
|
2025-11-12 14:04:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return await agentApi.sendAgentMessage(agentId, requestData, signal ? { signal } : undefined)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'send')
|
|
|
|
|
|
throw error
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// ==================== CHAT ACTIONS ====================
|
2025-09-16 02:18:34 +08:00
|
|
|
|
// 检查第一个对话是否为空
|
|
|
|
|
|
const isFirstChatEmpty = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (threads.value.length === 0) return false
|
2026-03-09 01:23:15 +08:00
|
|
|
|
const chatToReuse = getFirstNonPinnedChat(threads.value)
|
|
|
|
|
|
const messages = threadMessages.value[chatToReuse.id]
|
|
|
|
|
|
// 只有当消息已加载且为空时才返回 true
|
|
|
|
|
|
return messages !== undefined && messages.length === 0
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-09-16 02:18:34 +08:00
|
|
|
|
|
2026-03-08 22:33:24 +08:00
|
|
|
|
// 获取第一个非置顶的对话
|
|
|
|
|
|
const getFirstNonPinnedChat = (chatList) => {
|
2026-03-09 01:23:15 +08:00
|
|
|
|
if (!chatList || chatList.length === 0) return null
|
2026-03-08 22:33:24 +08:00
|
|
|
|
return chatList.find((chat) => !chat.is_pinned) || chatList[0]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果第一个对话为空,直接切换到第一个非置顶对话
|
2025-09-16 02:18:34 +08:00
|
|
|
|
const switchToFirstChatIfEmpty = async () => {
|
|
|
|
|
|
if (threads.value.length > 0 && isFirstChatEmpty()) {
|
2026-03-09 01:23:15 +08:00
|
|
|
|
const chatToReuse = getFirstNonPinnedChat(threads.value)
|
|
|
|
|
|
if (chatState.currentThreadId !== chatToReuse.id) {
|
|
|
|
|
|
await selectChat(chatToReuse.id)
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return true
|
2025-09-16 02:18:34 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
2025-09-16 02:18:34 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const createNewChat = async () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
!AgentValidator.validateAgentId(currentAgentId.value, '创建对话') ||
|
|
|
|
|
|
chatUIStore.creatingNewChat
|
|
|
|
|
|
)
|
|
|
|
|
|
return
|
2025-09-16 02:18:34 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果第一个对话为空,直接切换到第一个对话而不是创建新对话
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (await switchToFirstChatIfEmpty()) return
|
2025-09-16 02:18:34 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatUIStore.creatingNewChat = true
|
2025-05-15 22:34:32 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const newThread = await createThread(currentAgentId.value, '新的对话')
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (newThread) {
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// 中断之前线程的流式输出(如果存在)
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const previousThreadId = chatState.currentThreadId
|
2025-11-01 21:34:16 +08:00
|
|
|
|
if (previousThreadId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const previousThreadState = getThreadState(previousThreadId)
|
2025-11-01 21:34:16 +08:00
|
|
|
|
if (previousThreadState?.isStreaming && previousThreadState.streamAbortController) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
previousThreadState.streamAbortController.abort()
|
|
|
|
|
|
previousThreadState.isStreaming = false
|
|
|
|
|
|
previousThreadState.streamAbortController = null
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.currentThreadId = newThread.id
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'create')
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} finally {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatUIStore.creatingNewChat = false
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const selectChat = async (chatId) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
!AgentValidator.validateAgentIdWithError(
|
|
|
|
|
|
currentAgentId.value,
|
|
|
|
|
|
'选择对话',
|
|
|
|
|
|
handleValidationError
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// 中断之前线程的流式输出(如果存在)
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const previousThreadId = chatState.currentThreadId
|
2025-11-01 21:34:16 +08:00
|
|
|
|
if (previousThreadId && previousThreadId !== chatId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const previousThreadState = getThreadState(previousThreadId)
|
2025-11-01 21:34:16 +08:00
|
|
|
|
if (previousThreadState?.isStreaming && previousThreadState.streamAbortController) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
previousThreadState.streamAbortController.abort()
|
|
|
|
|
|
previousThreadState.isStreaming = false
|
|
|
|
|
|
previousThreadState.streamAbortController = null
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
2026-02-25 16:26:09 +08:00
|
|
|
|
// run 模式下仅断开 SSE 订阅,不取消后台运行任务
|
|
|
|
|
|
stopRunStreamSubscription(previousThreadId)
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.currentThreadId = chatId
|
|
|
|
|
|
chatUIStore.isLoadingMessages = true
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await fetchThreadMessages({ agentId: currentAgentId.value, threadId: chatId })
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'load')
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} finally {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatUIStore.isLoadingMessages = false
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await nextTick()
|
|
|
|
|
|
scrollController.scrollToBottomStaticForce()
|
2026-03-04 08:53:50 +08:00
|
|
|
|
await handleAgentStateRefresh(chatId)
|
2026-02-25 16:26:09 +08:00
|
|
|
|
await resumeActiveRunForThread(chatId)
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const deleteChat = async (chatId) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
!AgentValidator.validateAgentIdWithError(
|
|
|
|
|
|
currentAgentId.value,
|
|
|
|
|
|
'删除对话',
|
|
|
|
|
|
handleValidationError
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
return
|
2025-05-15 22:34:32 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await deleteThread(chatId)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (chatState.currentThreadId === chatId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatState.currentThreadId = null
|
2025-11-09 15:09:23 +08:00
|
|
|
|
// 如果删除的是当前对话,自动创建新对话
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await createNewChat()
|
2025-11-09 15:09:23 +08:00
|
|
|
|
} else if (chatsList.value.length > 0) {
|
2026-03-08 22:33:24 +08:00
|
|
|
|
// 如果删除的不是当前对话,选择第一个非置顶可用对话
|
|
|
|
|
|
await selectChat(getFirstNonPinnedChat(chatsList.value).id)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'delete')
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const renameChat = async (data) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
let { chatId, title } = data
|
|
|
|
|
|
if (
|
|
|
|
|
|
!AgentValidator.validateRenameOperation(
|
|
|
|
|
|
chatId,
|
|
|
|
|
|
title,
|
|
|
|
|
|
currentAgentId.value,
|
|
|
|
|
|
handleValidationError
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
return
|
|
|
|
|
|
if (title.length > 30) title = title.slice(0, 30)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await updateThread(chatId, title)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'rename')
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2026-03-06 20:29:58 +08:00
|
|
|
|
const togglePinChat = async (chatId) => {
|
|
|
|
|
|
const chat = chatsList.value.find((c) => c.id === chatId)
|
|
|
|
|
|
if (!chat) return
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 保存当前选中的对话ID
|
|
|
|
|
|
const prevChatId = currentChatId.value
|
|
|
|
|
|
|
|
|
|
|
|
await updateThread(chatId, null, !chat.is_pinned)
|
|
|
|
|
|
|
|
|
|
|
|
// 刷新对话列表
|
|
|
|
|
|
await loadChatsList()
|
|
|
|
|
|
|
|
|
|
|
|
// 恢复当前选中的对话
|
|
|
|
|
|
if (prevChatId) {
|
|
|
|
|
|
chatState.currentThreadId = prevChatId
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
handleChatError(error, 'pin')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
const handleSendMessage = async ({ image } = {}) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const text = userInput.value.trim()
|
|
|
|
|
|
if ((!text && !image) || !currentAgent.value || isProcessing.value) return
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
let threadId = currentChatId.value
|
2025-11-08 10:51:30 +08:00
|
|
|
|
if (!threadId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadId = await ensureActiveThread(text)
|
2025-11-08 10:51:30 +08:00
|
|
|
|
if (!threadId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
message.error('创建对话失败,请重试')
|
|
|
|
|
|
return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
userInput.value = ''
|
2025-11-12 14:04:34 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await nextTick()
|
|
|
|
|
|
scrollController.scrollToBottom(true)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threadState = getThreadState(threadId)
|
|
|
|
|
|
if (!threadState) return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-02-25 16:26:09 +08:00
|
|
|
|
if (useRunsApi) {
|
|
|
|
|
|
if ((threadMessages.value[threadId] || []).length === 0) {
|
|
|
|
|
|
const autoTitle = text.replace(/\s+/g, ' ').trim().slice(0, 255)
|
|
|
|
|
|
if (autoTitle) {
|
|
|
|
|
|
void updateThread(threadId, autoTitle).catch(() => {})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resetOnGoingConv(threadId)
|
|
|
|
|
|
threadState.isStreaming = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const runResp = await agentApi.createAgentRun(currentAgentId.value, {
|
|
|
|
|
|
query: text,
|
|
|
|
|
|
config: {
|
|
|
|
|
|
thread_id: threadId,
|
|
|
|
|
|
...(selectedAgentConfigId.value ? { agent_config_id: selectedAgentConfigId.value } : {})
|
|
|
|
|
|
},
|
|
|
|
|
|
image_content: image?.imageContent
|
|
|
|
|
|
})
|
|
|
|
|
|
const runId = runResp?.run_id
|
|
|
|
|
|
if (!runId) {
|
|
|
|
|
|
throw new Error('创建 run 失败:缺少 run_id')
|
|
|
|
|
|
}
|
|
|
|
|
|
await startRunStream(threadId, runId, 0)
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
threadState.isStreaming = false
|
|
|
|
|
|
handleChatError(error, 'send')
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadState.isStreaming = true
|
|
|
|
|
|
resetOnGoingConv(threadId)
|
|
|
|
|
|
threadState.streamAbortController = new AbortController()
|
2025-05-15 22:57:23 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
try {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const response = await sendMessage({
|
|
|
|
|
|
agentId: currentAgentId.value,
|
2025-12-19 04:04:48 +08:00
|
|
|
|
threadId: threadId,
|
2025-10-12 23:45:17 +08:00
|
|
|
|
text: text,
|
2025-11-12 14:04:34 +08:00
|
|
|
|
signal: threadState.streamAbortController?.signal,
|
2025-12-19 04:04:48 +08:00
|
|
|
|
imageData: image
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await handleAgentResponse(response, threadId)
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} catch (error) {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (error.name !== 'AbortError') {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('Stream error:', error)
|
|
|
|
|
|
handleChatError(error, 'send')
|
2025-12-19 02:22:29 +08:00
|
|
|
|
} else {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.warn('[Interrupted] Catch')
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadState.isStreaming = false
|
2025-12-19 02:22:29 +08:00
|
|
|
|
} finally {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadState.streamAbortController = null
|
2025-12-19 02:22:29 +08:00
|
|
|
|
// 异步加载历史记录,保持当前消息显示直到历史记录加载完成
|
2026-03-04 04:13:05 +08:00
|
|
|
|
fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId }).finally(() => {
|
|
|
|
|
|
// 历史记录加载完成后,安全地清空当前进行中的对话
|
|
|
|
|
|
resetOnGoingConv(threadId)
|
2026-03-05 23:06:43 +08:00
|
|
|
|
handleAgentStateRefresh(threadId)
|
2026-03-04 04:13:05 +08:00
|
|
|
|
scrollController.scrollToBottom()
|
|
|
|
|
|
})
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-10-06 21:44:17 +08:00
|
|
|
|
// 发送或中断
|
2025-12-19 04:04:48 +08:00
|
|
|
|
const handleSendOrStop = async (payload) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threadId = currentChatId.value
|
|
|
|
|
|
const threadState = getThreadState(threadId)
|
2026-02-25 16:26:09 +08:00
|
|
|
|
if (isProcessing.value && threadState) {
|
|
|
|
|
|
if (useRunsApi && threadState.activeRunId) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await agentApi.cancelAgentRun(threadState.activeRunId)
|
|
|
|
|
|
message.info('已发送取消请求')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
handleChatError(error, 'stop')
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-10-06 21:44:17 +08:00
|
|
|
|
|
2026-02-25 16:26:09 +08:00
|
|
|
|
if (threadState.streamAbortController) {
|
|
|
|
|
|
// 中断生成
|
|
|
|
|
|
threadState.streamAbortController.abort()
|
|
|
|
|
|
|
|
|
|
|
|
// 中断后刷新消息历史,确保显示最新的状态
|
|
|
|
|
|
try {
|
|
|
|
|
|
await fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId, delay: 500 })
|
|
|
|
|
|
message.info('已中断对话生成')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('刷新消息历史失败:', error)
|
|
|
|
|
|
message.info('已中断对话生成')
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
2025-10-06 21:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await handleSendMessage(payload)
|
|
|
|
|
|
}
|
2025-10-06 21:44:17 +08:00
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// ==================== 人工审批处理 ====================
|
2026-03-07 23:28:25 +08:00
|
|
|
|
const handleApprovalWithStream = async (answer) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threadId = approvalState.threadId
|
2025-11-01 21:34:16 +08:00
|
|
|
|
if (!threadId) {
|
2026-03-07 23:28:25 +08:00
|
|
|
|
message.error('无效的提问请求')
|
2026-01-15 06:01:34 +08:00
|
|
|
|
approvalState.showModal = false
|
|
|
|
|
|
return
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const threadState = getThreadState(threadId)
|
2025-11-01 21:34:16 +08:00
|
|
|
|
if (!threadState) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
message.error('无法找到对应的对话线程')
|
|
|
|
|
|
approvalState.showModal = false
|
|
|
|
|
|
return
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 使用审批 composable 处理审批
|
2026-03-07 23:28:25 +08:00
|
|
|
|
const response = await handleApproval(answer, currentAgentId.value, selectedAgentConfigId.value)
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!response) return // 如果 handleApproval 抛出错误,这里不会执行
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
|
|
|
|
|
// 处理流式响应
|
2026-02-25 16:26:09 +08:00
|
|
|
|
await handleAgentResponse(response, threadId)
|
2025-11-01 21:34:16 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
if (error.name !== 'AbortError') {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('Resume approval error:', error)
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
if (threadState) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
threadState.isStreaming = false
|
|
|
|
|
|
threadState.streamAbortController = null
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
2025-12-19 02:22:29 +08:00
|
|
|
|
|
|
|
|
|
|
// 异步加载历史记录,保持当前消息显示直到历史记录加载完成
|
2026-03-04 04:13:05 +08:00
|
|
|
|
fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId }).finally(() => {
|
|
|
|
|
|
resetOnGoingConv(threadId)
|
|
|
|
|
|
scrollController.scrollToBottom()
|
|
|
|
|
|
})
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2026-03-07 23:28:25 +08:00
|
|
|
|
const handleQuestionSubmit = (answer) => {
|
|
|
|
|
|
handleApprovalWithStream(answer)
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2026-03-07 23:28:25 +08:00
|
|
|
|
const handleQuestionCancel = () => {
|
|
|
|
|
|
handleApprovalWithStream('reject')
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2025-09-09 20:25:48 +08:00
|
|
|
|
// 处理示例问题点击
|
|
|
|
|
|
const handleExampleClick = (questionText) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
userInput.value = questionText
|
2025-09-09 20:25:48 +08:00
|
|
|
|
nextTick(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleSendMessage()
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-09-09 20:25:48 +08:00
|
|
|
|
|
2025-10-13 11:12:25 +08:00
|
|
|
|
const buildExportPayload = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const agentId = currentAgentId.value
|
|
|
|
|
|
let agentDescription = ''
|
2025-11-07 12:28:58 +08:00
|
|
|
|
if (agentId && agents.value && agents.value.length > 0) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const agent = agents.value.find((a) => a.id === agentId)
|
|
|
|
|
|
agentDescription = agent ? agent.description || '' : ''
|
2025-11-07 12:28:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-13 11:12:25 +08:00
|
|
|
|
const payload = {
|
|
|
|
|
|
chatTitle: currentThread.value?.title || '新对话',
|
|
|
|
|
|
agentName: currentAgentName.value || currentAgent.value?.name || '智能助手',
|
2025-11-07 12:28:58 +08:00
|
|
|
|
agentDescription: agentDescription || currentAgent.value?.description || '',
|
2025-10-13 11:12:25 +08:00
|
|
|
|
messages: conversations.value ? JSON.parse(JSON.stringify(conversations.value)) : [],
|
2026-01-15 06:01:34 +08:00
|
|
|
|
onGoingMessages: onGoingConvMessages.value
|
|
|
|
|
|
? JSON.parse(JSON.stringify(onGoingConvMessages.value))
|
|
|
|
|
|
: []
|
|
|
|
|
|
}
|
2025-10-13 11:12:25 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return payload
|
|
|
|
|
|
}
|
2025-06-27 01:48:09 +08:00
|
|
|
|
|
2025-10-13 11:12:25 +08:00
|
|
|
|
defineExpose({
|
|
|
|
|
|
getExportPayload: buildExportPayload
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-10-13 11:12:25 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
const toggleSidebar = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
chatUIStore.toggleSidebar()
|
|
|
|
|
|
}
|
|
|
|
|
|
const openAgentModal = () => emit('open-agent-modal')
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
2026-02-13 22:16:11 +08:00
|
|
|
|
const handleAgentStateRefresh = async (threadId = null) => {
|
|
|
|
|
|
if (!currentAgentId.value) return
|
2026-02-25 16:26:09 +08:00
|
|
|
|
const chatId = threadId || currentChatId.value
|
2026-02-13 22:16:11 +08:00
|
|
|
|
if (!chatId) return
|
2026-03-04 08:53:50 +08:00
|
|
|
|
await Promise.all([
|
|
|
|
|
|
fetchAgentState(currentAgentId.value, chatId),
|
|
|
|
|
|
refreshThreadFilesAndAttachments(chatId)
|
|
|
|
|
|
])
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-17 12:01:59 +08:00
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
const toggleAgentPanel = () => {
|
|
|
|
|
|
isAgentPanelOpen.value = !isAgentPanelOpen.value
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-02 21:44:10 +08:00
|
|
|
|
// 处理面板宽度调整(使用比例)
|
|
|
|
|
|
// 向右拖动(deltaX > 0)让面板变窄,向左拖动(deltaX < 0)让面板变宽
|
2026-01-31 17:04:30 +08:00
|
|
|
|
const handlePanelResize = (deltaX) => {
|
2026-02-02 21:44:10 +08:00
|
|
|
|
if (!panelWrapperRef.value) return
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化容器宽度
|
|
|
|
|
|
if (!panelContainerWidth) {
|
|
|
|
|
|
const container = document.querySelector('.chat-content-container')
|
|
|
|
|
|
panelContainerWidth = container ? container.clientWidth : window.innerWidth
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const currentWidth = panelWrapperRef.value.offsetWidth
|
|
|
|
|
|
// 反转 deltaX:向右拖(deltaX > 0)让面板变窄
|
|
|
|
|
|
const newWidth = currentWidth - deltaX
|
|
|
|
|
|
const newRatio = newWidth / panelContainerWidth
|
|
|
|
|
|
|
|
|
|
|
|
// 限制在合理范围内
|
|
|
|
|
|
if (newRatio >= minPanelRatio && newRatio <= maxPanelRatio) {
|
|
|
|
|
|
// 直接操作 DOM,不触发 Vue 响应式,使用 !important 确保不被覆盖
|
|
|
|
|
|
panelWrapperRef.value.style.setProperty('flex', `0 0 ${newWidth}px`, 'important')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 拖拽状态变化时,同步最终状态到 Vue 响应式数据
|
|
|
|
|
|
const handleResizingChange = (isResizingState) => {
|
|
|
|
|
|
isResizing.value = isResizingState
|
|
|
|
|
|
|
|
|
|
|
|
// 拖拽结束时,同步 DOM 宽度到响应式数据
|
|
|
|
|
|
if (!isResizingState && panelWrapperRef.value && panelContainerWidth) {
|
|
|
|
|
|
const finalWidth = panelWrapperRef.value.offsetWidth
|
|
|
|
|
|
panelRatio.value = finalWidth / panelContainerWidth
|
|
|
|
|
|
panelContainerWidth = 0 // 重置,供下次使用
|
|
|
|
|
|
}
|
2026-01-31 17:04:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== HELPER FUNCTIONS ====================
|
|
|
|
|
|
const getLastMessage = (conv) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!conv?.messages?.length) return null
|
2025-08-25 13:57:47 +08:00
|
|
|
|
for (let i = conv.messages.length - 1; i >= 0; i--) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (conv.messages[i].type === 'ai') return conv.messages[i]
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return null
|
|
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
const showMsgRefs = (msg) => {
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// 如果正在审批中,不显示 refs
|
|
|
|
|
|
if (approvalState.showModal) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果当前线程ID与审批线程ID匹配,但审批框已关闭(说明刚刚处理完审批)
|
|
|
|
|
|
// 且当前有新的流式处理正在进行,则不显示之前被中断的消息的 refs
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
approvalState.threadId &&
|
|
|
|
|
|
chatState.currentThreadId === approvalState.threadId &&
|
|
|
|
|
|
!approvalState.showModal &&
|
|
|
|
|
|
isProcessing
|
|
|
|
|
|
) {
|
|
|
|
|
|
return false
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 只有真正完成的消息才显示 refs
|
|
|
|
|
|
if (msg.isLast && msg.status === 'finished') {
|
2026-03-02 21:01:37 +08:00
|
|
|
|
return ['copy', 'sources']
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2026-02-24 14:22:11 +08:00
|
|
|
|
const getConversationSources = (conv) => {
|
|
|
|
|
|
return MessageProcessor.extractSourcesFromConversation(conv, availableKnowledgeBases.value)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== LIFECYCLE & WATCHERS ====================
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const loadChatsList = async () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const agentId = currentAgentId.value
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!agentId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.warn('No agent selected, cannot load chats list')
|
|
|
|
|
|
threads.value = []
|
|
|
|
|
|
chatState.currentThreadId = null
|
2026-03-04 08:53:50 +08:00
|
|
|
|
threadFilesMap.value = {}
|
|
|
|
|
|
threadAttachmentsMap.value = {}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2025-04-02 22:20:56 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await fetchThreads(agentId)
|
|
|
|
|
|
if (currentAgentId.value !== agentId) return
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果当前线程不在线程列表中,清空当前线程
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
chatState.currentThreadId &&
|
|
|
|
|
|
!threads.value.find((t) => t.id === chatState.currentThreadId)
|
|
|
|
|
|
) {
|
|
|
|
|
|
chatState.currentThreadId = null
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-08 22:33:24 +08:00
|
|
|
|
// 如果有线程但没有选中任何线程,自动选择第一个非置顶对话
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (threads.value.length > 0 && !chatState.currentThreadId) {
|
2026-03-08 22:33:24 +08:00
|
|
|
|
await selectChat(getFirstNonPinnedChat(threads.value).id)
|
2025-08-25 01:46:31 +08:00
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'load')
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-14 12:50:32 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const initAll = async () => {
|
2025-03-31 22:32:19 +08:00
|
|
|
|
try {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!agentStore.isInitialized) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await agentStore.initialize()
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
handleChatError(error, 'load')
|
2025-04-02 13:00:25 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-04-02 13:00:25 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
onMounted(async () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await initAll()
|
|
|
|
|
|
scrollController.enableAutoScroll()
|
|
|
|
|
|
})
|
2025-08-31 12:22:49 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
currentAgentId,
|
|
|
|
|
|
async (newAgentId, oldAgentId) => {
|
|
|
|
|
|
if (newAgentId !== oldAgentId) {
|
|
|
|
|
|
// 清理当前线程状态
|
|
|
|
|
|
chatState.currentThreadId = null
|
|
|
|
|
|
threadMessages.value = {}
|
2026-03-04 08:53:50 +08:00
|
|
|
|
threadFilesMap.value = {}
|
|
|
|
|
|
threadAttachmentsMap.value = {}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
// 清理所有线程状态
|
|
|
|
|
|
resetOnGoingConv()
|
|
|
|
|
|
|
|
|
|
|
|
if (newAgentId) {
|
|
|
|
|
|
await loadChatsList()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
threads.value = []
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true }
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
conversations,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
if (isProcessing.value) {
|
|
|
|
|
|
scrollController.scrollToBottom()
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{ deep: true, flush: 'post' }
|
|
|
|
|
|
)
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
2025-06-30 22:29:23 +08:00
|
|
|
|
@import '@/assets/css/main.css';
|
2025-12-19 04:04:48 +08:00
|
|
|
|
@import '@/assets/css/animations.less';
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
|
|
|
|
|
.chat-container {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
position: relative;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-31 22:32:19 +08:00
|
|
|
|
.chat {
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
overflow: hidden; /* Changed from overflow-x: hidden to overflow: hidden */
|
2025-03-31 22:32:19 +08:00
|
|
|
|
position: relative;
|
|
|
|
|
|
box-sizing: border-box;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
transition: all 0.3s ease;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
|
|
|
|
|
.chat-header {
|
|
|
|
|
|
user-select: none;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
// position: sticky; // Not needed if .chat is flex col and header is fixed height item
|
|
|
|
|
|
// top: 0;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
z-index: 10;
|
|
|
|
|
|
height: var(--header-height);
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
2025-08-08 22:57:14 +08:00
|
|
|
|
padding: 1rem 8px;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
flex-shrink: 0; /* Prevent header from shrinking */
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
.header__left,
|
|
|
|
|
|
.header__right {
|
2025-03-31 22:32:19 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
2025-11-23 19:42:51 +08:00
|
|
|
|
|
|
|
|
|
|
.switch-icon {
|
|
|
|
|
|
color: var(--gray-500);
|
|
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.agent-nav-btn:hover .switch-icon {
|
|
|
|
|
|
color: var(--main-500);
|
|
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
.chat-content-container {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
width: 100%;
|
2026-02-02 21:44:10 +08:00
|
|
|
|
contain: layout;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat-main {
|
2026-02-02 21:44:10 +08:00
|
|
|
|
flex: 1 1 0;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
overflow-y: auto; /* Scroll is here now */
|
|
|
|
|
|
position: relative;
|
2026-02-02 21:44:10 +08:00
|
|
|
|
transition:
|
|
|
|
|
|
flex-basis 0.3s cubic-bezier(0.4, 0, 0.2, 1),
|
|
|
|
|
|
width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
2026-01-31 14:16:53 +08:00
|
|
|
|
min-width: 0; /* Prevent flex item from overflowing */
|
2026-02-03 02:28:51 +08:00
|
|
|
|
|
|
|
|
|
|
scrollbar-width: none;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.agent-panel-wrapper {
|
2026-01-31 17:04:30 +08:00
|
|
|
|
flex: 0 0 auto;
|
2026-02-02 21:44:10 +08:00
|
|
|
|
height: calc(100% - 56px);
|
2026-01-24 15:24:25 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
z-index: 20;
|
2026-02-02 21:44:10 +08:00
|
|
|
|
margin: 28px 8px;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
margin-left: 0;
|
|
|
|
|
|
background: var(--gray-0);
|
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
box-shadow: 0 4px 20px var(--shadow-1);
|
2026-02-25 12:10:50 +08:00
|
|
|
|
border: 1px solid var(--gray-150);
|
2026-01-31 17:04:30 +08:00
|
|
|
|
min-width: 0;
|
2026-02-02 21:44:10 +08:00
|
|
|
|
will-change: flex-basis;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-25 23:00:03 +08:00
|
|
|
|
/* Workbench transition animations */
|
2026-02-02 21:44:10 +08:00
|
|
|
|
.agent-panel-wrapper {
|
|
|
|
|
|
transition: flex-basis 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
|
|
|
|
opacity: 0;
|
|
|
|
|
|
transform: translateX(10px);
|
|
|
|
|
|
margin-left: -16px;
|
2026-01-25 23:00:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-02 21:44:10 +08:00
|
|
|
|
.agent-panel-wrapper.is-visible {
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
transform: translateX(0);
|
|
|
|
|
|
margin-left: 0;
|
2026-01-25 23:00:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-02 21:44:10 +08:00
|
|
|
|
.agent-panel-wrapper.no-transition {
|
|
|
|
|
|
transition: none !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat-examples-input {
|
|
|
|
|
|
padding: 32px 0;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
h1 {
|
2026-02-02 21:44:10 +08:00
|
|
|
|
font-size: 1.2rem;
|
2025-08-09 23:18:19 +08:00
|
|
|
|
color: var(--gray-1000);
|
2026-02-02 21:44:10 +08:00
|
|
|
|
margin: 0;
|
2025-09-09 20:25:48 +08:00
|
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
}
|
2025-09-09 20:25:48 +08:00
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
.example-questions {
|
|
|
|
|
|
margin-top: 16px;
|
|
|
|
|
|
text-align: center;
|
2025-09-09 20:25:48 +08:00
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
.example-chips {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.example-chip {
|
|
|
|
|
|
padding: 6px 12px;
|
|
|
|
|
|
background: var(--gray-25);
|
|
|
|
|
|
// border: 1px solid var(--gray-100);
|
|
|
|
|
|
border-radius: 16px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
|
color: var(--gray-700);
|
|
|
|
|
|
transition: all 0.15s ease;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
max-width: 200px;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
|
// background: var(--main-25);
|
|
|
|
|
|
border-color: var(--main-200);
|
|
|
|
|
|
color: var(--main-700);
|
|
|
|
|
|
box-shadow: 0 0px 4px rgba(0, 0, 0, 0.03);
|
2025-09-09 20:25:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
&:active {
|
|
|
|
|
|
transform: translateY(0);
|
|
|
|
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
2025-09-09 20:25:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
.chat-loading {
|
|
|
|
|
|
padding: 0 50px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 20%;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
z-index: 9;
|
|
|
|
|
|
animation: slideInUp 0.5s ease-out;
|
2025-11-05 09:20:58 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
gap: 12px;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
|
|
span {
|
|
|
|
|
|
color: var(--gray-700);
|
2025-11-05 09:20:58 +08:00
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading-spinner {
|
|
|
|
|
|
width: 20px;
|
|
|
|
|
|
height: 20px;
|
|
|
|
|
|
border: 2px solid var(--gray-200);
|
|
|
|
|
|
border-top-color: var(--main-color);
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
animation: spin 0.8s linear infinite;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-31 22:32:19 +08:00
|
|
|
|
.chat-box {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
max-width: 800px;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
flex-grow: 1;
|
2026-01-27 21:46:10 +08:00
|
|
|
|
padding: 1rem 1.25rem;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
.conv-box {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 4px;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.bottom {
|
|
|
|
|
|
position: sticky;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
margin: 0 auto;
|
2026-01-24 15:24:25 +08:00
|
|
|
|
padding: 4px 1rem 0 1rem;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
background: var(--gray-0);
|
2025-10-12 23:45:17 +08:00
|
|
|
|
z-index: 1000;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
|
|
|
|
|
.message-input-wrapper {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
max-width: 800px;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
|
|
|
|
|
|
.bottom-actions {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.note {
|
|
|
|
|
|
font-size: small;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--gray-300);
|
2025-03-31 22:32:19 +08:00
|
|
|
|
margin: 4px 0;
|
|
|
|
|
|
user-select: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
|
|
|
|
|
|
&.start-screen {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 45%;
|
|
|
|
|
|
left: 50%;
|
|
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
|
|
bottom: auto;
|
|
|
|
|
|
max-width: 800px;
|
|
|
|
|
|
width: 90%;
|
|
|
|
|
|
background: transparent;
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
border-top: none;
|
|
|
|
|
|
z-index: 100; /* Ensure it's above other elements */
|
|
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading-dots {
|
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2025-08-09 23:18:19 +08:00
|
|
|
|
gap: 3px;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading-dots div {
|
2025-08-09 23:18:19 +08:00
|
|
|
|
width: 6px;
|
|
|
|
|
|
height: 6px;
|
|
|
|
|
|
background: linear-gradient(135deg, var(--main-color), var(--main-700));
|
2025-03-31 22:32:19 +08:00
|
|
|
|
border-radius: 50%;
|
2025-08-09 23:18:19 +08:00
|
|
|
|
animation: dotPulse 1.4s infinite ease-in-out both;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading-dots div:nth-child(1) {
|
|
|
|
|
|
animation-delay: -0.32s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading-dots div:nth-child(2) {
|
|
|
|
|
|
animation-delay: -0.16s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-09 23:18:19 +08:00
|
|
|
|
.loading-dots div:nth-child(3) {
|
|
|
|
|
|
animation-delay: 0s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-24 00:15:51 +08:00
|
|
|
|
.generating-status {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: flex-start;
|
2025-08-09 23:18:19 +08:00
|
|
|
|
padding: 1rem 0;
|
|
|
|
|
|
animation: fadeInUp 0.4s ease-out;
|
|
|
|
|
|
transition: all 0.2s;
|
2025-06-24 00:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.generating-indicator {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2025-08-09 23:18:19 +08:00
|
|
|
|
padding: 0.75rem 0rem;
|
2025-06-24 00:15:51 +08:00
|
|
|
|
|
|
|
|
|
|
.generating-text {
|
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
|
font-size: 14px;
|
2025-08-09 23:18:19 +08:00
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
letter-spacing: 0.025em;
|
2025-12-30 19:40:09 +08:00
|
|
|
|
/* 恢复灰色调:深灰 -> 亮灰(高光) -> 深灰 */
|
|
|
|
|
|
background: linear-gradient(
|
|
|
|
|
|
90deg,
|
|
|
|
|
|
var(--gray-700) 0%,
|
|
|
|
|
|
var(--gray-700) 40%,
|
|
|
|
|
|
var(--gray-300) 45%,
|
|
|
|
|
|
var(--gray-200) 50%,
|
|
|
|
|
|
var(--gray-300) 55%,
|
|
|
|
|
|
var(--gray-700) 60%,
|
|
|
|
|
|
var(--gray-700) 100%
|
|
|
|
|
|
);
|
|
|
|
|
|
background-size: 200% auto;
|
|
|
|
|
|
-webkit-background-clip: text;
|
|
|
|
|
|
background-clip: text;
|
|
|
|
|
|
color: transparent;
|
|
|
|
|
|
animation: waveFlash 2s linear infinite;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes waveFlash {
|
|
|
|
|
|
0% {
|
|
|
|
|
|
background-position: 200% center;
|
|
|
|
|
|
}
|
|
|
|
|
|
100% {
|
|
|
|
|
|
background-position: -200% center;
|
2025-06-24 00:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-13 11:12:25 +08:00
|
|
|
|
@media (max-width: 1800px) {
|
|
|
|
|
|
.chat-header {
|
2025-11-23 01:39:44 +08:00
|
|
|
|
background-color: var(--gray-0);
|
2025-10-13 11:12:25 +08:00
|
|
|
|
border-bottom: 1px solid var(--gray-100);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
|
.chat-header {
|
|
|
|
|
|
.header__left {
|
|
|
|
|
|
.text {
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-25 13:57:47 +08:00
|
|
|
|
</style>
|
2025-10-13 11:12:25 +08:00
|
|
|
|
|
|
|
|
|
|
<style lang="less">
|
2025-11-08 17:14:54 +08:00
|
|
|
|
.agent-nav-btn {
|
2025-10-13 11:12:25 +08:00
|
|
|
|
display: flex;
|
2026-01-22 12:15:46 +08:00
|
|
|
|
gap: 6px;
|
2026-01-15 04:54:53 +08:00
|
|
|
|
padding: 6px 8px;
|
|
|
|
|
|
height: 32px;
|
2025-10-13 11:12:25 +08:00
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
2026-01-22 11:16:15 +08:00
|
|
|
|
border-radius: 6px;
|
2025-10-13 11:12:25 +08:00
|
|
|
|
color: var(--gray-900);
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
width: auto;
|
|
|
|
|
|
font-size: 15px;
|
|
|
|
|
|
transition: background-color 0.3s;
|
2025-11-08 17:14:54 +08:00
|
|
|
|
border: none;
|
|
|
|
|
|
background: transparent;
|
2025-10-13 11:12:25 +08:00
|
|
|
|
|
2025-11-08 17:14:54 +08:00
|
|
|
|
&:hover:not(.is-disabled) {
|
2026-01-15 04:54:53 +08:00
|
|
|
|
background-color: var(--gray-100);
|
2025-10-13 11:12:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-08 17:14:54 +08:00
|
|
|
|
&.is-disabled {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
cursor: not-allowed;
|
|
|
|
|
|
opacity: 0.7;
|
2025-11-08 17:14:54 +08:00
|
|
|
|
pointer-events: none;
|
2025-11-08 13:59:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-13 11:12:25 +08:00
|
|
|
|
.nav-btn-icon {
|
2026-01-15 04:54:53 +08:00
|
|
|
|
height: 18px;
|
2025-10-13 11:12:25 +08:00
|
|
|
|
}
|
2025-11-08 13:59:56 +08:00
|
|
|
|
|
|
|
|
|
|
.loading-icon {
|
|
|
|
|
|
animation: spin 1s linear infinite;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
|
.hide-text {
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@media (min-width: 769px) {
|
|
|
|
|
|
.hide-text {
|
|
|
|
|
|
display: inline;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-14 12:50:32 +08:00
|
|
|
|
/* AgentState 按钮有内容时的样式 */
|
2025-12-17 23:39:53 +08:00
|
|
|
|
.agent-nav-btn.agent-state-btn.has-content:hover:not(.is-disabled) {
|
|
|
|
|
|
color: var(--main-700);
|
|
|
|
|
|
background-color: var(--main-20);
|
2025-11-14 12:50:32 +08:00
|
|
|
|
}
|
2026-01-24 15:24:25 +08:00
|
|
|
|
|
|
|
|
|
|
.agent-nav-btn.agent-state-btn.active {
|
|
|
|
|
|
color: var(--main-700);
|
|
|
|
|
|
background-color: var(--main-20);
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
</style>
|