2025-03-31 22:32:19 +08:00
|
|
|
|
<template>
|
2025-05-15 22:34:32 +08:00
|
|
|
|
<div class="chat-container" ref="chatContainerRef">
|
|
|
|
|
|
<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"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
@create-chat="createNewChat"
|
|
|
|
|
|
@select-chat="selectChat"
|
|
|
|
|
|
@delete-chat="deleteChat"
|
|
|
|
|
|
@rename-chat="renameChat"
|
|
|
|
|
|
@toggle-sidebar="toggleSidebar"
|
2025-08-11 21:29:33 +08:00
|
|
|
|
@open-agent-modal="openAgentModal"
|
2025-06-22 19:49:42 +08:00
|
|
|
|
:class="{
|
|
|
|
|
|
'floating-sidebar': isSmallContainer,
|
2025-11-08 13:59:56 +08:00
|
|
|
|
'sidebar-open': chatUIStore.isSidebarOpen,
|
|
|
|
|
|
'no-transition': localUIState.isInitialRender,
|
|
|
|
|
|
'collapsed': isSmallContainer && !chatUIStore.isSidebarOpen
|
2025-06-22 19:49:42 +08:00
|
|
|
|
}"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
/>
|
2025-11-08 13:59:56 +08:00
|
|
|
|
<div class="sidebar-backdrop" v-if="chatUIStore.isSidebarOpen && isSmallContainer" @click="toggleSidebar"></div>
|
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>
|
2025-11-08 13:59:56 +08:00
|
|
|
|
<div type="button" class="agent-nav-btn" v-if="!chatUIStore.isSidebarOpen" @click="toggleSidebar">
|
2025-10-13 11:12:25 +08:00
|
|
|
|
<PanelLeftOpen class="nav-btn-icon" size="18"/>
|
2025-05-15 22:34:32 +08:00
|
|
|
|
</div>
|
2025-11-23 19:42:51 +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"
|
|
|
|
|
|
>
|
2025-11-08 13:59:56 +08:00
|
|
|
|
<LoaderCircle v-if="chatUIStore.creatingNewChat" class="nav-btn-icon loading-icon" size="18"/>
|
|
|
|
|
|
<MessageCirclePlus v-else class="nav-btn-icon" size="18"/>
|
2025-10-13 11:12:25 +08:00
|
|
|
|
<span class="text" :class="{'hide-text': isMediumContainer}">新对话</span>
|
2025-03-31 23:02:05 +08:00
|
|
|
|
</div>
|
2025-11-23 19:42:51 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="!props.singleMode"
|
|
|
|
|
|
class="agent-nav-btn"
|
|
|
|
|
|
@click="openAgentModal"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span class="text">{{ currentAgentName || '选择智能体' }}</span>
|
|
|
|
|
|
<ChevronDown size="16" class="switch-icon" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-03-31 23:02:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="header__right">
|
2025-11-14 12:50:32 +08:00
|
|
|
|
<!-- AgentState 显示按钮 - 只在智能体支持 todo 或 files 能力时显示 -->
|
|
|
|
|
|
<AgentPopover
|
2025-11-17 12:01:59 +08:00
|
|
|
|
v-if="hasAgentStateContent"
|
2025-11-14 12:50:32 +08:00
|
|
|
|
v-model:visible="agentStatePopoverVisible"
|
|
|
|
|
|
:agent-state="currentAgentState"
|
2025-11-17 12:01:59 +08:00
|
|
|
|
@refresh="handleAgentStateRefresh"
|
2025-11-14 12:50:32 +08:00
|
|
|
|
>
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="agent-nav-btn agent-state-btn"
|
|
|
|
|
|
:class="{ 'has-content': hasAgentStateContent }"
|
|
|
|
|
|
:title="hasAgentStateContent ? '查看工作状态' : '暂无工作状态'"
|
|
|
|
|
|
>
|
2025-12-17 23:39:53 +08:00
|
|
|
|
<FolderDotIcon class="nav-btn-icon" size="18"/>
|
|
|
|
|
|
<span v-if="hasAgentStateContent" class="text">状态</span>
|
2025-11-14 12:50:32 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</AgentPopover>
|
2025-12-27 17:29:21 +08:00
|
|
|
|
<slot name="header-right" :is-medium-container="isMediumContainer"></slot>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
<!-- 加载状态:加载消息 -->
|
|
|
|
|
|
<div v-if="isLoadingMessages" class="chat-loading">
|
2025-11-05 09:20:58 +08:00
|
|
|
|
<div class="loading-spinner"></div>
|
|
|
|
|
|
<span>正在加载消息...</span>
|
2025-05-15 22:34:32 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
<div v-else-if="!conversations.length" class="chat-examples">
|
2025-11-07 12:28:58 +08:00
|
|
|
|
<div style="margin-bottom: 150px"></div>
|
|
|
|
|
|
<h1>您好,我是{{ currentAgentName }}!</h1>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</div>
|
2025-05-15 22:34:32 +08:00
|
|
|
|
<div class="chat-box" ref="messagesContainer">
|
2025-08-25 13:57:47 +08:00
|
|
|
|
<div class="conv-box" v-for="(conv, index) in conversations" :key="index">
|
2025-05-15 22:34:32 +08:00
|
|
|
|
<AgentMessageComponent
|
2025-08-25 13:57:47 +08:00
|
|
|
|
v-for="(message, msgIndex) in conv.messages"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
:message="message"
|
2025-08-25 13:57:47 +08:00
|
|
|
|
:key="msgIndex"
|
|
|
|
|
|
:is-processing="isProcessing && conv.status === 'streaming' && msgIndex === conv.messages.length - 1"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
:show-refs="showMsgRefs(message)"
|
|
|
|
|
|
@retry="retryMessage(message)"
|
|
|
|
|
|
>
|
|
|
|
|
|
</AgentMessageComponent>
|
2025-06-24 00:15:51 +08:00
|
|
|
|
<!-- 显示对话最后一个消息使用的模型 -->
|
|
|
|
|
|
<RefsComponent
|
2025-11-01 21:34:16 +08:00
|
|
|
|
v-if="shouldShowRefs(conv)"
|
2025-06-24 00:15:51 +08:00
|
|
|
|
:message="getLastMessage(conv)"
|
|
|
|
|
|
:show-refs="['model', 'copy']"
|
|
|
|
|
|
:is-latest-message="false"
|
|
|
|
|
|
/>
|
2025-05-15 22:34:32 +08:00
|
|
|
|
</div>
|
2025-06-24 00:15:51 +08:00
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
<!-- 生成中的加载状态 - 增强条件支持主聊天和resume流程 -->
|
2025-08-25 13:57:47 +08:00
|
|
|
|
<div class="generating-status" v-if="isProcessing && conversations.length > 0">
|
2025-06-24 00:15:51 +08:00
|
|
|
|
<div class="generating-indicator">
|
|
|
|
|
|
<div class="loading-dots">
|
|
|
|
|
|
<div></div>
|
|
|
|
|
|
<div></div>
|
|
|
|
|
|
<div></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span class="generating-text">正在生成回复...</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</div>
|
2025-12-19 04:04:48 +08:00
|
|
|
|
<div class="bottom" :class="{ 'start-screen': !conversations.length }">
|
2025-11-01 21:34:16 +08:00
|
|
|
|
<!-- 人工审批弹窗 - 放在输入框上方 -->
|
|
|
|
|
|
<HumanApprovalModal
|
|
|
|
|
|
:visible="approvalState.showModal"
|
|
|
|
|
|
:question="approvalState.question"
|
|
|
|
|
|
:operation="approvalState.operation"
|
|
|
|
|
|
@approve="handleApprove"
|
|
|
|
|
|
@reject="handleReject"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
<div class="message-input-wrapper">
|
|
|
|
|
|
<AgentInputArea
|
2025-11-12 14:04:34 +08:00
|
|
|
|
ref="messageInputRef"
|
2025-03-31 22:32:19 +08:00
|
|
|
|
v-model="userInput"
|
2025-08-25 13:57:47 +08:00
|
|
|
|
:is-loading="isProcessing"
|
2025-05-15 22:34:32 +08:00
|
|
|
|
:disabled="!currentAgent"
|
2025-10-06 21:44:17 +08:00
|
|
|
|
:send-button-disabled="(!userInput || !currentAgent) && !isProcessing"
|
2025-10-13 11:12:25 +08:00
|
|
|
|
placeholder="输入问题..."
|
2025-12-19 04:04:48 +08:00
|
|
|
|
:supports-file-upload="supportsFileUpload"
|
|
|
|
|
|
:agent-id="currentAgentId"
|
|
|
|
|
|
:thread-id="currentChatId"
|
|
|
|
|
|
:ensure-thread="ensureActiveThread"
|
2025-10-06 21:44:17 +08:00
|
|
|
|
@send="handleSendOrStop"
|
2025-12-19 04:04:48 +08:00
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 示例问题 -->
|
|
|
|
|
|
<div class="example-questions" v-if="!conversations.length && exampleQuestions.length > 0">
|
|
|
|
|
|
<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>
|
2025-08-25 13:57:47 +08:00
|
|
|
|
<p class="note">请注意辨别内容的可靠性</p>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-11-14 12:50:32 +08:00
|
|
|
|
|
|
|
|
|
|
</div>
|
2025-03-31 22:32:19 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-10-13 11:12:25 +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'
|
2025-12-17 23:39:53 +08:00
|
|
|
|
import { PanelLeftOpen, MessageCirclePlus, LoaderCircle, FolderDotIcon, ChevronDown } from 'lucide-vue-next';
|
2025-08-31 14:39:28 +08:00
|
|
|
|
import { handleChatError, handleValidationError } from '@/utils/errorHandler';
|
2025-08-25 13:57:47 +08:00
|
|
|
|
import { ScrollController } from '@/utils/scrollController';
|
|
|
|
|
|
import { AgentValidator } from '@/utils/agentValidator';
|
2025-08-25 01:46:31 +08:00
|
|
|
|
import { useAgentStore } from '@/stores/agent';
|
2025-11-08 13:59:56 +08:00
|
|
|
|
import { useChatUIStore } from '@/stores/chatUI';
|
2025-08-25 01:46:31 +08:00
|
|
|
|
import { storeToRefs } from 'pinia';
|
2025-08-31 14:39:28 +08:00
|
|
|
|
import { MessageProcessor } from '@/utils/messageProcessor';
|
|
|
|
|
|
import { agentApi, threadApi } from '@/apis';
|
2025-11-01 21:34:16 +08:00
|
|
|
|
import HumanApprovalModal from '@/components/HumanApprovalModal.vue';
|
|
|
|
|
|
import { useApproval } from '@/composables/useApproval';
|
2025-12-19 04:04:48 +08:00
|
|
|
|
import { useAgentStreamHandler } from '@/composables/useAgentStreamHandler';
|
2025-11-14 12:50:32 +08:00
|
|
|
|
import AgentPopover from '@/components/AgentPopover.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 }
|
2025-03-31 23:02:05 +08:00
|
|
|
|
});
|
2025-08-11 21:29:33 +08:00
|
|
|
|
const emit = defineEmits(['open-config', 'open-agent-modal']);
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== STORE MANAGEMENT ====================
|
2025-08-25 01:46:31 +08:00
|
|
|
|
const agentStore = useAgentStore();
|
2025-11-08 13:59:56 +08:00
|
|
|
|
const chatUIStore = useChatUIStore();
|
2025-08-25 01:46:31 +08:00
|
|
|
|
const {
|
|
|
|
|
|
agents,
|
2025-08-31 14:39:28 +08:00
|
|
|
|
selectedAgentId,
|
|
|
|
|
|
defaultAgentId,
|
2025-08-25 01:46:31 +08:00
|
|
|
|
} = storeToRefs(agentStore);
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// ==================== LOCAL CHAT & UI STATE ====================
|
2025-08-25 13:57:47 +08:00
|
|
|
|
const userInput = ref('');
|
2025-08-31 14:39:28 +08:00
|
|
|
|
|
2025-09-09 20:25:48 +08:00
|
|
|
|
// 从智能体元数据获取示例问题
|
|
|
|
|
|
const exampleQuestions = computed(() => {
|
2025-11-07 12:28:58 +08:00
|
|
|
|
const agentId = currentAgentId.value;
|
|
|
|
|
|
let examples = [];
|
|
|
|
|
|
if (agentId && agents.value && agents.value.length > 0) {
|
|
|
|
|
|
const agent = agents.value.find(a => a.id === agentId);
|
|
|
|
|
|
examples = agent ? (agent.examples || []) : [];
|
|
|
|
|
|
}
|
2025-09-09 20:25:48 +08:00
|
|
|
|
return examples.map((text, index) => ({
|
|
|
|
|
|
id: index + 1,
|
|
|
|
|
|
text: text
|
|
|
|
|
|
}));
|
|
|
|
|
|
});
|
|
|
|
|
|
|
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: {}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
// 业务状态(保留在组件本地)
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const chatState = reactive({
|
|
|
|
|
|
currentThreadId: null,
|
|
|
|
|
|
// 以threadId为键的线程状态
|
|
|
|
|
|
threadStates: {}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 组件级别的线程和消息状态
|
|
|
|
|
|
const threads = ref([]);
|
|
|
|
|
|
const threadMessages = ref({});
|
|
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
// 本地 UI 状态(仅在本组件使用)
|
|
|
|
|
|
const localUIState = reactive({
|
2025-08-31 14:39:28 +08:00
|
|
|
|
isInitialRender: true,
|
2025-08-25 13:57:47 +08:00
|
|
|
|
containerWidth: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-14 12:50:32 +08:00
|
|
|
|
// AgentState Popover 状态
|
|
|
|
|
|
const agentStatePopoverVisible = ref(false);
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== COMPUTED PROPERTIES ====================
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const currentAgentId = computed(() => {
|
|
|
|
|
|
if (props.singleMode) {
|
|
|
|
|
|
return props.agentId || defaultAgentId.value;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return selectedAgentId.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-07 12:28:58 +08:00
|
|
|
|
const currentAgentName = computed(() => {
|
2025-10-13 11:12:25 +08:00
|
|
|
|
const agentId = currentAgentId.value;
|
2025-11-07 12:28:58 +08:00
|
|
|
|
if (agentId && agents.value && agents.value.length > 0) {
|
|
|
|
|
|
const agent = agents.value.find(a => a.id === agentId);
|
|
|
|
|
|
return agent ? agent.name : '智能体';
|
|
|
|
|
|
}
|
2025-12-07 18:25:45 +08:00
|
|
|
|
return '智能体加载中……';
|
2025-09-18 20:51:50 +08:00
|
|
|
|
});
|
2025-09-09 20:25:48 +08:00
|
|
|
|
|
2025-11-07 12:38:29 +08:00
|
|
|
|
const currentAgent = computed(() => {
|
|
|
|
|
|
if (!currentAgentId.value || !agents.value || !agents.value.length) return null;
|
|
|
|
|
|
return agents.value.find(a => a.id === currentAgentId.value) || null;
|
|
|
|
|
|
});
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const chatsList = computed(() => threads.value || []);
|
|
|
|
|
|
const currentChatId = computed(() => chatState.currentThreadId);
|
|
|
|
|
|
const currentThread = computed(() => {
|
|
|
|
|
|
if (!currentChatId.value) return null;
|
|
|
|
|
|
return threads.value.find(thread => thread.id === currentChatId.value) || null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-08 10:51:30 +08:00
|
|
|
|
// 检查当前智能体是否支持文件上传
|
|
|
|
|
|
const supportsFileUpload = computed(() => {
|
|
|
|
|
|
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(() => {
|
|
|
|
|
|
if (!currentAgent.value) return false;
|
|
|
|
|
|
const capabilities = currentAgent.value.capabilities || [];
|
|
|
|
|
|
return capabilities.includes('todo');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const supportsFiles = computed(() => {
|
|
|
|
|
|
if (!currentAgent.value) return false;
|
|
|
|
|
|
const capabilities = currentAgent.value.capabilities || [];
|
|
|
|
|
|
return capabilities.includes('files');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// AgentState 相关计算属性
|
|
|
|
|
|
const currentAgentState = computed(() => {
|
|
|
|
|
|
return currentChatId.value ? getThreadState(currentChatId.value)?.agentState || null : null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-17 12:01:59 +08:00
|
|
|
|
const countFiles = (files) => {
|
|
|
|
|
|
if (!Array.isArray(files)) return 0;
|
|
|
|
|
|
let c = 0;
|
|
|
|
|
|
for (const item of files) {
|
|
|
|
|
|
if (item && typeof item === 'object') c += Object.keys(item).length;
|
|
|
|
|
|
}
|
|
|
|
|
|
return c;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-14 12:50:32 +08:00
|
|
|
|
const hasAgentStateContent = computed(() => {
|
2025-11-17 12:01:59 +08:00
|
|
|
|
const s = currentAgentState.value;
|
|
|
|
|
|
if (!s) return false;
|
|
|
|
|
|
const todoCount = Array.isArray(s.todos) ? s.todos.length : 0;
|
|
|
|
|
|
const fileCount = countFiles(s.files);
|
|
|
|
|
|
return todoCount > 0 || fileCount > 0;
|
2025-11-14 12:50:32 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const currentThreadMessages = computed(() => threadMessages.value[currentChatId.value] || []);
|
|
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// 计算是否显示Refs组件的条件
|
|
|
|
|
|
const shouldShowRefs = computed(() => {
|
|
|
|
|
|
return (conv) => {
|
|
|
|
|
|
return getLastMessage(conv) &&
|
|
|
|
|
|
conv.status !== 'streaming' &&
|
|
|
|
|
|
!approvalState.showModal &&
|
|
|
|
|
|
!(approvalState.threadId &&
|
|
|
|
|
|
chatState.currentThreadId === approvalState.threadId &&
|
|
|
|
|
|
isProcessing.value);
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 当前线程状态的computed属性
|
|
|
|
|
|
const currentThreadState = computed(() => {
|
|
|
|
|
|
return getThreadState(currentChatId.value);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const onGoingConvMessages = computed(() => {
|
|
|
|
|
|
const threadState = currentThreadState.value;
|
|
|
|
|
|
if (!threadState || !threadState.onGoingConv) return [];
|
2025-09-03 03:00:25 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const msgs = Object.values(threadState.onGoingConv.msgChunks).map(MessageProcessor.mergeMessageChunk);
|
|
|
|
|
|
return msgs.length > 0
|
|
|
|
|
|
? MessageProcessor.convertToolResultToMessages(msgs).filter(msg => msg.type !== 'tool')
|
|
|
|
|
|
: [];
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-19 14:41:23 +08:00
|
|
|
|
const historyConversations = computed(() => {
|
|
|
|
|
|
return MessageProcessor.convertServerHistoryToMessages(currentThreadMessages.value);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const conversations = computed(() => {
|
2025-12-19 14:41:23 +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'
|
|
|
|
|
|
};
|
|
|
|
|
|
return [...historyConvs, onGoingConv];
|
|
|
|
|
|
}
|
|
|
|
|
|
return historyConvs;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
const isLoadingMessages = computed(() => chatUIStore.isLoadingMessages);
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const isStreaming = computed(() => {
|
|
|
|
|
|
const threadState = currentThreadState.value;
|
|
|
|
|
|
return threadState ? threadState.isStreaming : false;
|
|
|
|
|
|
});
|
2025-11-05 09:20:58 +08:00
|
|
|
|
const isProcessing = computed(() => isStreaming.value);
|
2025-11-08 13:59:56 +08:00
|
|
|
|
const isSmallContainer = computed(() => localUIState.containerWidth <= 520);
|
|
|
|
|
|
const isMediumContainer = computed(() => localUIState.containerWidth <= 768);
|
2025-08-10 21:58:41 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== SCROLL & RESIZE HANDLING ====================
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const chatContainerRef = ref(null);
|
2025-08-25 13:57:47 +08:00
|
|
|
|
const scrollController = new ScrollController('.chat');
|
2025-05-15 22:34:32 +08:00
|
|
|
|
let resizeObserver = null;
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
if (chatContainerRef.value) {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
localUIState.containerWidth = chatContainerRef.value.offsetWidth;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
resizeObserver = new ResizeObserver(entries => {
|
|
|
|
|
|
for (let entry of entries) {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
localUIState.containerWidth = entry.contentRect.width;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
resizeObserver.observe(chatContainerRef.value);
|
|
|
|
|
|
}
|
2025-06-24 00:15:51 +08:00
|
|
|
|
const chatContainer = document.querySelector('.chat');
|
|
|
|
|
|
if (chatContainer) {
|
2025-08-25 13:57:47 +08:00
|
|
|
|
chatContainer.addEventListener('scroll', scrollController.handleScroll, { passive: true });
|
2025-06-24 00:15:51 +08:00
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
});
|
2025-11-08 13:59:56 +08:00
|
|
|
|
setTimeout(() => { localUIState.isInitialRender = false; }, 300);
|
2025-05-15 22:34:32 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
2025-08-25 13:57:47 +08:00
|
|
|
|
if (resizeObserver) resizeObserver.disconnect();
|
|
|
|
|
|
scrollController.cleanup();
|
2025-11-14 12:50:32 +08:00
|
|
|
|
// 清理所有线程状态
|
2025-08-31 14:39:28 +08:00
|
|
|
|
resetOnGoingConv();
|
2025-08-25 01:46:31 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// ==================== THREAD STATE MANAGEMENT ====================
|
|
|
|
|
|
// 获取指定线程的状态,如果不存在则创建
|
|
|
|
|
|
const getThreadState = (threadId) => {
|
|
|
|
|
|
if (!threadId) return null;
|
|
|
|
|
|
if (!chatState.threadStates[threadId]) {
|
|
|
|
|
|
chatState.threadStates[threadId] = {
|
|
|
|
|
|
isStreaming: false,
|
|
|
|
|
|
streamAbortController: null,
|
2025-11-14 12:50:32 +08:00
|
|
|
|
onGoingConv: createOnGoingConvState(),
|
|
|
|
|
|
agentState: null // 添加 agentState 字段
|
2025-08-31 14:39:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
return chatState.threadStates[threadId];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 清理指定线程的状态
|
|
|
|
|
|
const cleanupThreadState = (threadId) => {
|
|
|
|
|
|
if (!threadId) return;
|
|
|
|
|
|
const threadState = chatState.threadStates[threadId];
|
|
|
|
|
|
if (threadState) {
|
|
|
|
|
|
if (threadState.streamAbortController) {
|
|
|
|
|
|
threadState.streamAbortController.abort();
|
|
|
|
|
|
}
|
|
|
|
|
|
delete chatState.threadStates[threadId];
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== STREAM HANDLING LOGIC ====================
|
2025-12-19 02:22:29 +08:00
|
|
|
|
const resetOnGoingConv = (threadId = null) => {
|
|
|
|
|
|
console.log(`🔄 [RESET] Resetting on going conversation: ${new Date().toLocaleTimeString()}.${new Date().getMilliseconds()}`, threadId);
|
|
|
|
|
|
|
|
|
|
|
|
const targetThreadId = threadId || currentChatId.value;
|
|
|
|
|
|
|
|
|
|
|
|
if (targetThreadId) {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 清理指定线程的状态
|
2025-12-19 02:22:29 +08:00
|
|
|
|
const threadState = getThreadState(targetThreadId);
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (threadState) {
|
|
|
|
|
|
if (threadState.streamAbortController) {
|
|
|
|
|
|
threadState.streamAbortController.abort();
|
|
|
|
|
|
threadState.streamAbortController = null;
|
|
|
|
|
|
}
|
2025-12-19 02:22:29 +08:00
|
|
|
|
|
|
|
|
|
|
// 直接重置对话状态
|
2025-11-12 11:00:39 +08:00
|
|
|
|
threadState.onGoingConv = createOnGoingConvState();
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-12-19 02:22:29 +08:00
|
|
|
|
// 如果没有当前线程,清理所有线程状态
|
|
|
|
|
|
Object.keys(chatState.threadStates).forEach(tid => {
|
|
|
|
|
|
cleanupThreadState(tid);
|
|
|
|
|
|
});
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== 线程管理方法 ====================
|
|
|
|
|
|
// 获取当前智能体的线程列表
|
|
|
|
|
|
const fetchThreads = async (agentId = null) => {
|
|
|
|
|
|
const targetAgentId = agentId || currentAgentId.value;
|
|
|
|
|
|
if (!targetAgentId) return;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
chatUIStore.isLoadingThreads = true;
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const fetchedThreads = await threadApi.getThreads(targetAgentId);
|
|
|
|
|
|
threads.value = fetchedThreads || [];
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to fetch threads:', error);
|
|
|
|
|
|
handleChatError(error, 'fetch');
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
} finally {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
chatUIStore.isLoadingThreads = false;
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 创建新线程
|
|
|
|
|
|
const createThread = async (agentId, title = '新的对话') => {
|
|
|
|
|
|
if (!agentId) return null;
|
|
|
|
|
|
|
|
|
|
|
|
chatState.isCreatingThread = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
const thread = await threadApi.createThread(agentId, title);
|
|
|
|
|
|
if (thread) {
|
|
|
|
|
|
threads.value.unshift(thread);
|
|
|
|
|
|
threadMessages.value[thread.id] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
return thread;
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to create thread:', error);
|
|
|
|
|
|
handleChatError(error, 'create');
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
chatState.isCreatingThread = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 删除线程
|
|
|
|
|
|
const deleteThread = async (threadId) => {
|
|
|
|
|
|
if (!threadId) return;
|
|
|
|
|
|
|
|
|
|
|
|
chatState.isDeletingThread = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
await threadApi.deleteThread(threadId);
|
|
|
|
|
|
threads.value = threads.value.filter(thread => thread.id !== threadId);
|
|
|
|
|
|
delete threadMessages.value[threadId];
|
|
|
|
|
|
|
|
|
|
|
|
if (chatState.currentThreadId === threadId) {
|
|
|
|
|
|
chatState.currentThreadId = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to delete thread:', error);
|
|
|
|
|
|
handleChatError(error, 'delete');
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
chatState.isDeletingThread = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 更新线程标题
|
|
|
|
|
|
const updateThread = async (threadId, title) => {
|
|
|
|
|
|
if (!threadId || !title) return;
|
|
|
|
|
|
|
|
|
|
|
|
chatState.isRenamingThread = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
await threadApi.updateThread(threadId, title);
|
|
|
|
|
|
const thread = threads.value.find(t => t.id === threadId);
|
|
|
|
|
|
if (thread) {
|
|
|
|
|
|
thread.title = title;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to update thread:', error);
|
|
|
|
|
|
handleChatError(error, 'update');
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
chatState.isRenamingThread = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 获取线程消息
|
2025-11-12 11:00:39 +08:00
|
|
|
|
const fetchThreadMessages = async ({ agentId, threadId, delay = 0 }) => {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!threadId || !agentId) return;
|
|
|
|
|
|
|
2025-11-12 11:00:39 +08:00
|
|
|
|
// 如果指定了延迟,等待指定时间(用于确保后端数据库事务提交)
|
|
|
|
|
|
if (delay > 0) {
|
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const response = await agentApi.getAgentHistory(agentId, threadId);
|
2025-12-19 02:22:29 +08:00
|
|
|
|
console.log(`🔄 [FETCH] Thread messages: ${new Date().toLocaleTimeString()}.${new Date().getMilliseconds()}`, response);
|
2025-08-31 14:39:28 +08:00
|
|
|
|
threadMessages.value[threadId] = response.history || [];
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
handleChatError(error, 'load');
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-17 12:01:59 +08:00
|
|
|
|
const fetchAgentState = async (agentId, threadId) => {
|
|
|
|
|
|
if (!agentId || !threadId) return;
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await agentApi.getAgentState(agentId, threadId);
|
|
|
|
|
|
const ts = getThreadState(threadId);
|
|
|
|
|
|
if (ts) ts.agentState = res.agent_state || null;
|
|
|
|
|
|
} catch (error) {}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-08 10:51:30 +08:00
|
|
|
|
const ensureActiveThread = async (title = '新的对话') => {
|
|
|
|
|
|
if (currentChatId.value) return currentChatId.value;
|
|
|
|
|
|
try {
|
|
|
|
|
|
const newThread = await createThread(currentAgentId.value, title || '新的对话');
|
|
|
|
|
|
if (newThread) {
|
|
|
|
|
|
chatState.currentThreadId = newThread.id;
|
|
|
|
|
|
return newThread.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
// createThread 已处理错误提示
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// ==================== 审批功能管理 ====================
|
|
|
|
|
|
const { approvalState, handleApproval, processApprovalInStream } = useApproval({
|
|
|
|
|
|
getThreadState,
|
|
|
|
|
|
resetOnGoingConv,
|
|
|
|
|
|
fetchThreadMessages
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
const { handleAgentResponse } = useAgentStreamHandler({
|
|
|
|
|
|
getThreadState,
|
|
|
|
|
|
processApprovalInStream,
|
|
|
|
|
|
currentAgentId,
|
|
|
|
|
|
supportsTodo,
|
|
|
|
|
|
supportsFiles
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
// 发送消息并处理流式响应
|
2025-11-12 14:04: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) {
|
|
|
|
|
|
const error = new Error("Missing agent, thread, or message text");
|
|
|
|
|
|
handleChatError(error, 'send');
|
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是新对话,用消息内容作为标题
|
|
|
|
|
|
if ((threadMessages.value[threadId] || []).length === 0) {
|
|
|
|
|
|
updateThread(threadId, text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const requestData = {
|
|
|
|
|
|
query: text,
|
|
|
|
|
|
config: {
|
|
|
|
|
|
thread_id: threadId,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-12 14:04:34 +08:00
|
|
|
|
// 如果有图片,添加到请求中
|
|
|
|
|
|
if (imageData && imageData.imageContent) {
|
|
|
|
|
|
requestData.image_content = imageData.imageContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
2025-10-12 23:45:17 +08:00
|
|
|
|
return await agentApi.sendAgentMessage(agentId, requestData, signal ? { signal } : undefined);
|
2025-08-31 14:39:28 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
handleChatError(error, 'send');
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== CHAT ACTIONS ====================
|
2025-09-16 02:18:34 +08:00
|
|
|
|
// 检查第一个对话是否为空
|
|
|
|
|
|
const isFirstChatEmpty = () => {
|
|
|
|
|
|
if (threads.value.length === 0) return false;
|
|
|
|
|
|
const firstThread = threads.value[0];
|
|
|
|
|
|
const firstThreadMessages = threadMessages.value[firstThread.id] || [];
|
|
|
|
|
|
return firstThreadMessages.length === 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 如果第一个对话为空,直接切换到第一个对话
|
|
|
|
|
|
const switchToFirstChatIfEmpty = async () => {
|
|
|
|
|
|
if (threads.value.length > 0 && isFirstChatEmpty()) {
|
|
|
|
|
|
await selectChat(threads.value[0].id);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const createNewChat = async () => {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
if (!AgentValidator.validateAgentId(currentAgentId.value, '创建对话') || chatUIStore.creatingNewChat) return;
|
2025-09-16 02:18:34 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果第一个对话为空,直接切换到第一个对话而不是创建新对话
|
|
|
|
|
|
if (await switchToFirstChatIfEmpty()) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 只有当当前对话是第一个对话且为空时,才阻止创建新对话
|
|
|
|
|
|
const currentThreadIndex = threads.value.findIndex(thread => thread.id === currentChatId.value);
|
|
|
|
|
|
if (currentChatId.value && conversations.value.length === 0 && currentThreadIndex === 0) return;
|
2025-04-02 22:20:56 +08:00
|
|
|
|
|
2025-11-08 13:59:56 +08:00
|
|
|
|
chatUIStore.creatingNewChat = true;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
try {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const newThread = await createThread(currentAgentId.value, '新的对话');
|
|
|
|
|
|
if (newThread) {
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// 中断之前线程的流式输出(如果存在)
|
|
|
|
|
|
const previousThreadId = chatState.currentThreadId;
|
|
|
|
|
|
if (previousThreadId) {
|
|
|
|
|
|
const previousThreadState = getThreadState(previousThreadId);
|
|
|
|
|
|
if (previousThreadState?.isStreaming && previousThreadState.streamAbortController) {
|
|
|
|
|
|
previousThreadState.streamAbortController.abort();
|
|
|
|
|
|
previousThreadState.isStreaming = false;
|
|
|
|
|
|
previousThreadState.streamAbortController = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
chatState.currentThreadId = newThread.id;
|
|
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} catch (error) {
|
2025-08-25 13:57:47 +08:00
|
|
|
|
handleChatError(error, 'create');
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} finally {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
chatUIStore.creatingNewChat = false;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const selectChat = async (chatId) => {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!AgentValidator.validateAgentIdWithError(currentAgentId.value, '选择对话', handleValidationError)) return;
|
|
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// 中断之前线程的流式输出(如果存在)
|
|
|
|
|
|
const previousThreadId = chatState.currentThreadId;
|
|
|
|
|
|
if (previousThreadId && previousThreadId !== chatId) {
|
|
|
|
|
|
const previousThreadState = getThreadState(previousThreadId);
|
|
|
|
|
|
if (previousThreadState?.isStreaming && previousThreadState.streamAbortController) {
|
|
|
|
|
|
previousThreadState.streamAbortController.abort();
|
|
|
|
|
|
previousThreadState.isStreaming = false;
|
|
|
|
|
|
previousThreadState.streamAbortController = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
chatState.currentThreadId = chatId;
|
2025-11-08 13:59:56 +08:00
|
|
|
|
chatUIStore.isLoadingMessages = true;
|
2025-08-31 14:39:28 +08:00
|
|
|
|
try {
|
|
|
|
|
|
await fetchThreadMessages({ agentId: currentAgentId.value, threadId: chatId });
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
handleChatError(error, 'load');
|
|
|
|
|
|
} finally {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
chatUIStore.isLoadingMessages = false;
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-27 11:52:49 +08:00
|
|
|
|
await nextTick();
|
|
|
|
|
|
scrollController.scrollToBottomStaticForce();
|
2025-12-04 10:11:28 +08:00
|
|
|
|
await fetchAgentState(currentAgentId.value, chatId);
|
2025-03-31 22:32:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const deleteChat = async (chatId) => {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!AgentValidator.validateAgentIdWithError(currentAgentId.value, '删除对话', handleValidationError)) return;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
try {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
await deleteThread(chatId);
|
|
|
|
|
|
if (chatState.currentThreadId === chatId) {
|
|
|
|
|
|
chatState.currentThreadId = null;
|
2025-11-09 15:09:23 +08:00
|
|
|
|
// 如果删除的是当前对话,自动创建新对话
|
|
|
|
|
|
await createNewChat();
|
|
|
|
|
|
} else if (chatsList.value.length > 0) {
|
|
|
|
|
|
// 如果删除的不是当前对话,选择第一个可用对话
|
|
|
|
|
|
await selectChat(chatsList.value[0].id);
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} catch (error) {
|
2025-08-25 13:57:47 +08:00
|
|
|
|
handleChatError(error, 'delete');
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
const renameChat = async (data) => {
|
2025-06-06 10:54:48 +08:00
|
|
|
|
let { chatId, title } = data;
|
2025-08-31 14:39:28 +08:00
|
|
|
|
if (!AgentValidator.validateRenameOperation(chatId, title, currentAgentId.value, handleValidationError)) return;
|
2025-08-25 13:57:47 +08:00
|
|
|
|
if (title.length > 30) title = title.slice(0, 30);
|
|
|
|
|
|
try {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
await updateThread(chatId, title);
|
2025-08-25 13:57:47 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
handleChatError(error, 'rename');
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
2025-08-25 13:57:47 +08:00
|
|
|
|
};
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
const handleSendMessage = async ({ image } = {}) => {
|
|
|
|
|
|
console.log('AgentChatComponent: handleSendMessage payload image:', image);
|
2025-08-25 13:57:47 +08:00
|
|
|
|
const text = userInput.value.trim();
|
2025-12-19 04:04:48 +08:00
|
|
|
|
if ((!text && !image) || !currentAgent.value || isProcessing.value) return;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-11-08 10:51:30 +08:00
|
|
|
|
let threadId = currentChatId.value;
|
|
|
|
|
|
if (!threadId) {
|
|
|
|
|
|
threadId = await ensureActiveThread(text);
|
|
|
|
|
|
if (!threadId) {
|
|
|
|
|
|
message.error('创建对话失败,请重试');
|
2025-08-31 14:39:28 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
userInput.value = '';
|
2025-11-12 14:04:34 +08:00
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
await nextTick();
|
2025-08-31 14:39:28 +08:00
|
|
|
|
scrollController.scrollToBottom(true);
|
|
|
|
|
|
|
|
|
|
|
|
const threadState = getThreadState(threadId);
|
|
|
|
|
|
if (!threadState) return;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2025-08-31 14:39:28 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-19 04:04:48 +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') {
|
2025-12-19 02:22:29 +08:00
|
|
|
|
console.error('Stream error:', error);
|
2025-08-31 14:39:28 +08:00
|
|
|
|
handleChatError(error, 'send');
|
2025-12-19 02:22:29 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
console.warn("[Interrupted] Catch");
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
threadState.isStreaming = false;
|
2025-12-19 02:22:29 +08:00
|
|
|
|
} finally {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
threadState.streamAbortController = null;
|
2025-12-19 02:22:29 +08:00
|
|
|
|
// 异步加载历史记录,保持当前消息显示直到历史记录加载完成
|
|
|
|
|
|
fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId, delay: 500 })
|
|
|
|
|
|
.finally(() => {
|
|
|
|
|
|
// 历史记录加载完成后,安全地清空当前进行中的对话
|
|
|
|
|
|
resetOnGoingConv(threadId);
|
|
|
|
|
|
scrollController.scrollToBottom();
|
|
|
|
|
|
});
|
2025-05-15 22:34:32 +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) => {
|
2025-10-06 21:44:17 +08:00
|
|
|
|
const threadId = currentChatId.value;
|
|
|
|
|
|
const threadState = getThreadState(threadId);
|
|
|
|
|
|
if (isProcessing.value && threadState && threadState.streamAbortController) {
|
|
|
|
|
|
// 中断生成
|
|
|
|
|
|
threadState.streamAbortController.abort();
|
|
|
|
|
|
|
|
|
|
|
|
// 中断后刷新消息历史,确保显示最新的状态
|
|
|
|
|
|
try {
|
2025-12-17 18:28:54 +08:00
|
|
|
|
await fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId, delay: 500 });
|
2025-10-06 21:44:17 +08:00
|
|
|
|
message.info('已中断对话生成');
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('刷新消息历史失败:', error);
|
|
|
|
|
|
message.info('已中断对话生成');
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
await handleSendMessage(payload);
|
2025-10-06 21:44:17 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
// ==================== 人工审批处理 ====================
|
|
|
|
|
|
const handleApprovalWithStream = async (approved) => {
|
|
|
|
|
|
console.log('🔄 [STREAM] Starting resume stream processing');
|
|
|
|
|
|
|
|
|
|
|
|
const threadId = approvalState.threadId;
|
|
|
|
|
|
if (!threadId) {
|
|
|
|
|
|
message.error('无效的审批请求');
|
|
|
|
|
|
approvalState.showModal = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const threadState = getThreadState(threadId);
|
|
|
|
|
|
if (!threadState) {
|
|
|
|
|
|
message.error('无法找到对应的对话线程');
|
|
|
|
|
|
approvalState.showModal = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 使用审批 composable 处理审批
|
|
|
|
|
|
const response = await handleApproval(approved, currentAgentId.value);
|
|
|
|
|
|
|
|
|
|
|
|
if (!response) return; // 如果 handleApproval 抛出错误,这里不会执行
|
|
|
|
|
|
|
|
|
|
|
|
console.log('🔄 [STREAM] Processing resume streaming response');
|
|
|
|
|
|
|
|
|
|
|
|
// 处理流式响应
|
2025-12-19 04:04:48 +08:00
|
|
|
|
await handleAgentResponse(response, threadId, (chunk) => {
|
|
|
|
|
|
console.log('🔄 [STREAM] Processing chunk:', chunk);
|
|
|
|
|
|
});
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
|
|
|
|
|
console.log('🔄 [STREAM] Resume stream processing completed');
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('❌ [STREAM] Resume stream failed:', error);
|
|
|
|
|
|
if (error.name !== 'AbortError') {
|
|
|
|
|
|
console.error('Resume approval error:', error);
|
|
|
|
|
|
// handleChatError 已在 useApproval 中调用
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
console.log('🔄 [STREAM] Cleaning up streaming state');
|
|
|
|
|
|
if (threadState) {
|
|
|
|
|
|
threadState.isStreaming = false;
|
|
|
|
|
|
threadState.streamAbortController = null;
|
|
|
|
|
|
}
|
2025-12-19 02:22:29 +08:00
|
|
|
|
|
|
|
|
|
|
// 异步加载历史记录,保持当前消息显示直到历史记录加载完成
|
|
|
|
|
|
fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId, delay: 500 })
|
|
|
|
|
|
.finally(() => {
|
|
|
|
|
|
// 历史记录加载完成后,安全地清空当前进行中的对话
|
|
|
|
|
|
resetOnGoingConv(threadId);
|
|
|
|
|
|
scrollController.scrollToBottom();
|
|
|
|
|
|
});
|
2025-11-01 21:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleApprove = () => {
|
|
|
|
|
|
handleApprovalWithStream(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleReject = () => {
|
|
|
|
|
|
handleApprovalWithStream(false);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-09 20:25:48 +08:00
|
|
|
|
// 处理示例问题点击
|
|
|
|
|
|
const handleExampleClick = (questionText) => {
|
|
|
|
|
|
userInput.value = questionText;
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
handleSendMessage();
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-13 11:12:25 +08:00
|
|
|
|
const buildExportPayload = () => {
|
2025-11-07 12:28:58 +08:00
|
|
|
|
const agentId = currentAgentId.value;
|
|
|
|
|
|
let agentDescription = '';
|
|
|
|
|
|
if (agentId && agents.value && agents.value.length > 0) {
|
|
|
|
|
|
const agent = agents.value.find(a => a.id === agentId);
|
|
|
|
|
|
agentDescription = agent ? (agent.description || '') : '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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)) : [],
|
|
|
|
|
|
onGoingMessages: onGoingConvMessages.value ? JSON.parse(JSON.stringify(onGoingConvMessages.value)) : []
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return payload;
|
2025-06-27 01:48:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-13 11:12:25 +08:00
|
|
|
|
defineExpose({
|
|
|
|
|
|
getExportPayload: buildExportPayload
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
const toggleSidebar = () => {
|
2025-11-08 13:59:56 +08:00
|
|
|
|
chatUIStore.toggleSidebar();
|
2025-03-31 22:32:19 +08:00
|
|
|
|
};
|
2025-08-25 13:57:47 +08:00
|
|
|
|
const openAgentModal = () => emit('open-agent-modal');
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
2025-11-17 12:01:59 +08:00
|
|
|
|
const handleAgentStateRefresh = async () => {
|
|
|
|
|
|
if (!currentAgentId.value || !currentChatId.value) return;
|
|
|
|
|
|
await fetchAgentState(currentAgentId.value, currentChatId.value);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== HELPER FUNCTIONS ====================
|
|
|
|
|
|
const getLastMessage = (conv) => {
|
|
|
|
|
|
if (!conv?.messages?.length) return null;
|
|
|
|
|
|
for (let i = conv.messages.length - 1; i >= 0; i--) {
|
|
|
|
|
|
if (conv.messages[i].type === 'ai') return conv.messages[i];
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
2025-08-25 13:57:47 +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) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果当前线程ID与审批线程ID匹配,但审批框已关闭(说明刚刚处理完审批)
|
|
|
|
|
|
// 且当前有新的流式处理正在进行,则不显示之前被中断的消息的 refs
|
|
|
|
|
|
if (approvalState.threadId &&
|
|
|
|
|
|
chatState.currentThreadId === approvalState.threadId &&
|
|
|
|
|
|
!approvalState.showModal &&
|
|
|
|
|
|
isProcessing) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 只有真正完成的消息才显示 refs
|
|
|
|
|
|
if (msg.isLast && msg.status === 'finished') {
|
|
|
|
|
|
return ['copy'];
|
|
|
|
|
|
}
|
2025-08-25 13:57:47 +08:00
|
|
|
|
return false;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-25 13:57:47 +08:00
|
|
|
|
// ==================== LIFECYCLE & WATCHERS ====================
|
2025-08-31 14:39:28 +08:00
|
|
|
|
const loadChatsList = async () => {
|
|
|
|
|
|
const agentId = currentAgentId.value;
|
|
|
|
|
|
if (!agentId) {
|
|
|
|
|
|
console.warn('No agent selected, cannot load chats list');
|
|
|
|
|
|
threads.value = [];
|
|
|
|
|
|
chatState.currentThreadId = null;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-02 22:20:56 +08:00
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
try {
|
2025-08-31 14:39:28 +08:00
|
|
|
|
await fetchThreads(agentId);
|
|
|
|
|
|
if (currentAgentId.value !== agentId) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 如果当前线程不在线程列表中,清空当前线程
|
|
|
|
|
|
if (chatState.currentThreadId && !threads.value.find(t => t.id === chatState.currentThreadId)) {
|
|
|
|
|
|
chatState.currentThreadId = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有线程但没有选中任何线程,自动选择第一个
|
|
|
|
|
|
if (threads.value.length > 0 && !chatState.currentThreadId) {
|
|
|
|
|
|
await selectChat(threads.value[0].id);
|
2025-08-25 01:46:31 +08:00
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
} catch (error) {
|
2025-08-25 13:57:47 +08:00
|
|
|
|
handleChatError(error, 'load');
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
2025-08-25 13:57:47 +08:00
|
|
|
|
};
|
2025-03-31 22:32:19 +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) {
|
|
|
|
|
|
await agentStore.initialize();
|
2025-05-15 22:34:32 +08:00
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
} catch (error) {
|
2025-08-25 13:57:47 +08:00
|
|
|
|
handleChatError(error, 'load');
|
2025-04-02 13:00:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
await initAll();
|
2025-08-27 11:52:49 +08:00
|
|
|
|
scrollController.enableAutoScroll();
|
2025-12-21 16:23:19 +08:00
|
|
|
|
});
|
2025-08-27 11:52:49 +08:00
|
|
|
|
|
2025-08-31 14:39:28 +08:00
|
|
|
|
watch(currentAgentId, async (newAgentId, oldAgentId) => {
|
|
|
|
|
|
if (newAgentId !== oldAgentId) {
|
|
|
|
|
|
// 清理当前线程状态
|
|
|
|
|
|
chatState.currentThreadId = null;
|
|
|
|
|
|
threadMessages.value = {};
|
|
|
|
|
|
// 清理所有线程状态
|
|
|
|
|
|
resetOnGoingConv();
|
|
|
|
|
|
|
|
|
|
|
|
if (newAgentId) {
|
|
|
|
|
|
await loadChatsList();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
threads.value = [];
|
|
|
|
|
|
}
|
2025-08-31 12:22:49 +08:00
|
|
|
|
}
|
2025-08-31 14:39:28 +08:00
|
|
|
|
}, { immediate: true });
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-11-01 21:34:16 +08:00
|
|
|
|
|
2025-08-31 12:22:49 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.sidebar-backdrop {
|
|
|
|
|
|
display: none; /* 默认隐藏,通过v-if控制显示 */
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
background-color: rgba(0, 0, 0, 0.4);
|
|
|
|
|
|
z-index: 99;
|
|
|
|
|
|
animation: fadeIn 0.3s ease;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.floating-sidebar {
|
|
|
|
|
|
position: absolute !important;
|
2025-12-27 17:29:21 +08:00
|
|
|
|
z-index: 1001;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
height: 100%;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
transform: translateX(0);
|
|
|
|
|
|
transition: transform 0.3s ease;
|
|
|
|
|
|
width: 80% !important;
|
|
|
|
|
|
max-width: 300px;
|
|
|
|
|
|
|
2025-05-18 17:58:27 +08:00
|
|
|
|
&.no-transition {
|
|
|
|
|
|
transition: none !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
|
&.collapsed {
|
|
|
|
|
|
transform: translateX(-100%);
|
|
|
|
|
|
}
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat {
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
overflow-x: hidden;
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
overflow-y: scroll;
|
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;
|
|
|
|
|
|
position: sticky;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
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;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
2025-11-23 19:42:51 +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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat-examples {
|
|
|
|
|
|
padding: 0 50px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
position: absolute;
|
2025-12-19 04:04:48 +08:00
|
|
|
|
bottom: 65%;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
z-index: 9;
|
|
|
|
|
|
animation: slideInUp 0.5s ease-out;
|
|
|
|
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
|
|
margin-bottom: 20px;
|
2025-08-09 23:18:19 +08:00
|
|
|
|
font-size: 1.3rem;
|
|
|
|
|
|
color: var(--gray-1000);
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
p {
|
2025-08-09 23:18:19 +08:00
|
|
|
|
font-size: 1.1rem;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
color: var(--gray-700);
|
|
|
|
|
|
}
|
2025-08-09 23:18:19 +08:00
|
|
|
|
|
2025-09-09 20:25:48 +08:00
|
|
|
|
.agent-icons {
|
|
|
|
|
|
height: 180px;
|
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
padding: 1rem 2rem;
|
|
|
|
|
|
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;
|
|
|
|
|
|
padding: 4px 2rem 0 2rem;
|
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-03-31 22:32:19 +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-sidebar.collapsed {
|
|
|
|
|
|
width: 0;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat-header {
|
|
|
|
|
|
.header__left {
|
|
|
|
|
|
.text {
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-31 22:32:19 +08:00
|
|
|
|
@media (max-width: 520px) {
|
2025-05-15 22:34:32 +08:00
|
|
|
|
.sidebar-backdrop {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-31 22:32:19 +08:00
|
|
|
|
.chat-box {
|
|
|
|
|
|
padding: 1rem 1rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.bottom {
|
|
|
|
|
|
padding: 0.5rem 0.5rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat-header {
|
2025-08-24 22:32:37 +08:00
|
|
|
|
padding: 0.5rem 0 !important;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
2025-06-22 19:49:42 +08:00
|
|
|
|
.floating-sidebar {
|
2025-05-15 22:34:32 +08:00
|
|
|
|
position: fixed;
|
|
|
|
|
|
z-index: 100;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
|
|
|
|
transform: translateX(0);
|
|
|
|
|
|
transition: transform 0.3s ease;
|
|
|
|
|
|
width: 80% !important;
|
|
|
|
|
|
max-width: 300px;
|
|
|
|
|
|
|
|
|
|
|
|
&.collapsed {
|
|
|
|
|
|
transform: translateX(-100%);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.hide-text {
|
|
|
|
|
|
display: none;
|
2025-03-31 22:32:19 +08:00
|
|
|
|
}
|
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;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
padding: 6px 14px;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
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) {
|
2025-10-13 11:12:25 +08:00
|
|
|
|
background-color: var(--gray-50);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
height: 24px;
|
|
|
|
|
|
}
|
2025-11-08 13:59:56 +08:00
|
|
|
|
|
|
|
|
|
|
.loading-icon {
|
|
|
|
|
|
animation: spin 1s linear infinite;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
|
</style>
|