AiAssistantModal.vue 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466
  1. <template>
  2. <a-modal
  3. :visible="props.visible"
  4. @cancel="emit('close')"
  5. :width="modalWidth"
  6. :footer="null"
  7. destroyOnClose
  8. :closable="showControls"
  9. :zIndex="props.zIndex"
  10. :class="['ai-assistant-modal', { fullscreen: isFullscreen }]"
  11. >
  12. <template #title>
  13. <div :class="['draggable-title', { 'no-drag': isFullscreen }]" @mousedown="onDragStart">"通安智风"大模型</div>
  14. </template>
  15. <!-- 最大化/还原按钮 -->
  16. <div v-if="showControls" class="maximize-btn" @click="toggleFullscreen">
  17. <div :class="['maximize-icon', { minimized: isFullscreen }]"></div>
  18. </div>
  19. <!-- 收起/展开按钮 -->
  20. <div class="collapse-btn" @click="togglePanel">
  21. <div :class="['collapse-icon', { collapsed: panelCollapsed }]"></div>
  22. </div>
  23. <div class="ai-container">
  24. <!-- 左侧任务列表 -->
  25. <div :class="['task-panel-wrapper', { collapsed: panelCollapsed }]">
  26. <TaskListPanel
  27. :taskList="taskList"
  28. :currentTaskId="currentTaskId"
  29. @switch-task="switchTask"
  30. @create-task="createNewTask"
  31. @delete-task="handleDeleteTask"
  32. @pin-task="handlePinTask"
  33. @toggle-skill="toggleSkillPanel"
  34. @toggle-sub-agents="toggleSubAgentPanel"
  35. @toggle-schedules="toggleSchedulePanel"
  36. />
  37. </div>
  38. <!-- 右侧内容区:根据 activePanel 切换显示 -->
  39. <!-- 聊天区域 -->
  40. <template v-if="activePanel === 'chat'">
  41. <div class="chat-panel">
  42. <!-- 顶部任务选择器 -->
  43. <ChatHeader
  44. :currentTask="currentTask"
  45. :panelCollapsed="panelCollapsed"
  46. :canGoPrev="canGoPrev"
  47. :canGoNext="canGoNext"
  48. :currentWordUrl="currentWordUrl"
  49. @go-to-prev="goToPrev"
  50. @go-to-next="goToNext"
  51. @create-task="createNewTask"
  52. @save-title="handleSaveTitle"
  53. @download-word="downloadWordReport"
  54. />
  55. <!-- 附件列表面板 -->
  56. <FileListPanel :visible="showFileList" :files="getCurrentTaskFiles()" @close="showFileList = false" @file-click="openFilePreview" />
  57. <!-- 消息列表 -->
  58. <ChatMessages
  59. ref="chatMessagesRef"
  60. :messages="messages"
  61. @file-preview="openFilePreview"
  62. @download-word="downloadWordFile"
  63. @open-file-preview="handleOpenFilePreview"
  64. @ask-user-submit="handleAskUserSubmit"
  65. @ask-user-cancel="handleAskUserCancel"
  66. @agent-detail-click="handleAgentDetailClick"
  67. @open-markdown-tab="openMarkdownPreviewTab"
  68. @delete-message="handleDeleteMessage"
  69. />
  70. <!-- 任务进度条 -->
  71. <TodoListBar v-if="showTodoBar" :todos="currentTodos" />
  72. <!-- 输入区域 -->
  73. <ChatInputArea
  74. ref="chatInputRef"
  75. v-model="inputMessage"
  76. :pendingFile="pendingFile"
  77. :loading="loading || !!currentPendingApproval"
  78. :streaming="streaming"
  79. :contextUsed="contextUsed"
  80. :contextMax="contextMax"
  81. :contextPercent="contextPercent"
  82. :contextBreakdown="contextBreakdown"
  83. :usageLimit="usageToday?.limit_tokens ?? 0"
  84. :usageSpent="usageToday?.spent_tokens ?? 0"
  85. :usageRemaining="usageToday?.remaining_tokens ?? 0"
  86. :usageByModel="usageToday?.by_model ?? []"
  87. :initialThinkLevel="thinkLevel"
  88. :initialEditMode="editMode"
  89. :taskList="taskList"
  90. :currentTaskId="currentTaskId"
  91. @send="handleSendMessage"
  92. @stop="stopStreaming"
  93. @file-upload="triggerFileUpload"
  94. @file-change="handleFileUpload"
  95. @remove-pending-file="removePendingFile"
  96. @pending-file-preview="openFilePreview"
  97. @think-level-change="handleThinkLevelChange"
  98. @edit-mode-change="handleEditModeChange"
  99. @update:selected-sessions="handleUpdateSelectedSessions"
  100. @update:selected-skill="handleUpdateSelectedSkill"
  101. />
  102. </div>
  103. <!-- 右侧辅助面板(标签页容器,与 chat-panel 并列,带滑入滑出动画) -->
  104. <Transition name="right-panel-slide" @after-leave="onPanelLeaveEnd">
  105. <RightPanelTabs
  106. v-if="currentRightPanels.tabs.length > 0"
  107. :tabs="currentRightPanels.tabs"
  108. :activeTabId="currentRightPanels.activeTabId"
  109. :messages="messages"
  110. @switch-tab="activateTab"
  111. @close-tab="closeTab"
  112. @save-success="handleSaveSuccess"
  113. @schedule-deleted="handleScheduleDeleted"
  114. @schedule-updated="handleScheduleUpdated"
  115. @open-schedule-session="handleOpenScheduleSession"
  116. @open-markdown-tab="openMarkdownPreviewTab"
  117. />
  118. </Transition>
  119. </template>
  120. <!-- 技能面板 -->
  121. <div v-if="activePanel === 'skill'" class="right-panel full">
  122. <SkillPanel @close="activePanel = 'chat'" />
  123. </div>
  124. <!-- 子智能体面板 -->
  125. <div v-if="activePanel === 'sub-agents'" class="right-panel full">
  126. <SubAgentPanel @close="activePanel = 'chat'" />
  127. </div>
  128. <!-- 定时任务面板 -->
  129. <div v-if="activePanel === 'schedules'" class="right-panel full">
  130. <SchedulePanel
  131. ref="schedulePanelRef"
  132. @close="activePanel = 'chat'"
  133. @open-session="handleOpenScheduleSession"
  134. @data-changed="fetchScheduleListForDetail"
  135. />
  136. </div>
  137. </div>
  138. </a-modal>
  139. </template>
  140. <script setup lang="ts">
  141. import { ref, nextTick, watch, computed, onBeforeUnmount } from 'vue';
  142. import dayjs from 'dayjs';
  143. import {
  144. unifiedStream,
  145. reviewPdfStream,
  146. chatResumeStream,
  147. getHistoryList,
  148. getDetail,
  149. deleteSession,
  150. deleteMessage,
  151. pinSession,
  152. editSessionTitle,
  153. getContext,
  154. switchThinking,
  155. getModelMsg,
  156. getSessionMode,
  157. putSessionMode,
  158. getTodayUsage,
  159. StreamError,
  160. } from '../api';
  161. import { message, Modal } from 'ant-design-vue';
  162. import TaskListPanel from './chatModal/TaskListPanel.vue';
  163. import ChatHeader from './chatModal/ChatHeader.vue';
  164. import FileListPanel from './chatModal/FileListPanel.vue';
  165. import ChatMessages from './chatModal/ChatMessages.vue';
  166. import type { AgentDetailData } from './chatModal/ChatMessages.vue';
  167. import ChatInputArea from './chatModal/ChatInputArea.vue';
  168. import TodoListBar from './chatModal/TodoListBar.vue';
  169. import SkillPanel from './chatModal/SkillPanel.vue';
  170. import SubAgentPanel from './chatModal/SubAgentPanel.vue';
  171. import SchedulePanel from './chatModal/SchedulePanel.vue';
  172. import RightPanelTabs from './chatModal/RightPanelTabs.vue';
  173. import { getScheduleList } from '../api';
  174. import type { TodayUsage } from '../api';
  175. import type { AttachedFile, Message, Task, RightPanelTab, RightPanelState, SseEvent } from './chatModal/types';
  176. import { isTextFile, isVideoFile, isAudioFile, isWordFile, isExcelFile, isCsvFile } from './chatModal/utils';
  177. interface Props {
  178. visible: boolean;
  179. // 初始即全屏显示(首页等嵌入场景)
  180. defaultFullscreen?: boolean;
  181. // 是否显示窗口控制按钮(最大化/还原、关闭)
  182. showControls?: boolean;
  183. zIndex?: number;
  184. }
  185. interface Emits {
  186. (e: 'close'): void;
  187. }
  188. const props = withDefaults(defineProps<Props>(), {
  189. defaultFullscreen: false,
  190. showControls: true,
  191. });
  192. const emit = defineEmits<Emits>();
  193. const taskList = ref<Task[]>([]);
  194. // 已从接口拉取过的会话 id,用于识别流式期间后端新建的会话
  195. const knownApiSessionIds = new Set<string>();
  196. // 从接口获取会话列表
  197. const fetchSessionList = async () => {
  198. try {
  199. const res = await getHistoryList({});
  200. const sessions = res?.sessions || res?.data || [];
  201. if (Array.isArray(sessions)) {
  202. const apiTasks: Task[] = sessions.map((item: { session_id: string; title: string; updated_at: string; sort_order?: number }) => ({
  203. id: item.session_id,
  204. name: item.title || '未命名会话',
  205. sessionId: item.session_id,
  206. messages: [],
  207. attachedFiles: [],
  208. updatedAt: item.updated_at,
  209. sortOrder: item.sort_order,
  210. }));
  211. // Build lookup maps for O(1) access
  212. const existingTaskMap = new Map(taskList.value.map((t) => [t.id, t]));
  213. const apiTaskIds = new Set(apiTasks.map((t) => t.id));
  214. // 流式中的空白任务:后端已为其创建会话,但前端要等流结束才拿到 session_id。
  215. // 该会话在接口里是一条全新记录,归并回空白任务而不是单独插入,避免列表出现重复条目
  216. let blankStreamingTask: Task | null = taskList.value.find((t) => !t.sessionId && t.isStreaming) || null;
  217. const mergedTasks: Task[] = [];
  218. for (const apiTask of apiTasks) {
  219. if (blankStreamingTask && (blankStreamingTask.pendingSessionId === apiTask.id || !knownApiSessionIds.has(apiTask.id))) {
  220. blankStreamingTask.pendingSessionId = apiTask.id;
  221. blankStreamingTask.name = apiTask.name;
  222. blankStreamingTask.updatedAt = apiTask.updatedAt;
  223. blankStreamingTask.sortOrder = apiTask.sortOrder;
  224. blankStreamingTask = null;
  225. continue;
  226. }
  227. const existing = existingTaskMap.get(apiTask.id);
  228. if (existing) {
  229. // 原地更新以保持对象引用,避免流式回调持有的任务引用失效(isStreaming 等状态丢失)
  230. existing.name = apiTask.name;
  231. existing.updatedAt = apiTask.updatedAt;
  232. existing.sortOrder = apiTask.sortOrder;
  233. mergedTasks.push(existing);
  234. } else {
  235. mergedTasks.push(apiTask);
  236. }
  237. }
  238. apiTasks.forEach((apiTask) => knownApiSessionIds.add(apiTask.id));
  239. const localOnlyTasks = taskList.value.filter((t) => !t.sessionId && !apiTaskIds.has(t.id));
  240. taskList.value = [...localOnlyTasks, ...mergedTasks];
  241. return mergedTasks;
  242. }
  243. } catch (error) {
  244. console.error('获取会话列表失败:', error);
  245. }
  246. return [];
  247. };
  248. const currentTaskId = ref('');
  249. const chatInputRef = ref<InstanceType<typeof ChatInputArea>>();
  250. const chatMessagesRef = ref<InstanceType<typeof ChatMessages>>();
  251. const showFileList = ref(false);
  252. const activePanel = ref<'chat' | 'skill' | 'sub-agents' | 'schedules'>('chat');
  253. const scheduleListForDetail = ref<any[]>([]);
  254. const fetchScheduleListForDetail = async () => {
  255. try {
  256. const res = await getScheduleList();
  257. scheduleListForDetail.value = res?.tasks || res?.data || (Array.isArray(res) ? res : []);
  258. } catch {
  259. scheduleListForDetail.value = [];
  260. }
  261. };
  262. const pendingFile = ref<AttachedFile | null>(null);
  263. const activeFileReader = ref<FileReader | null>(null);
  264. const messages = ref<Message[]>([]);
  265. const usageToday = ref<TodayUsage | null>(null);
  266. const fetchTodayUsage = async () => {
  267. try {
  268. const res = await getTodayUsage();
  269. if (res && typeof res === 'object') {
  270. usageToday.value = res;
  271. }
  272. } catch (e) {
  273. console.error('获取今日用量失败:', e);
  274. }
  275. };
  276. const contextUsed = ref(0);
  277. const contextMax = ref(1000000);
  278. const contextPercent = ref(0);
  279. const thinkLevel = ref('off');
  280. const editMode = ref('full');
  281. const contextBreakdown = ref({ messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 });
  282. const currentTodos = ref<Array<{ content: string; status: string }>>([]);
  283. const showTodoBar = ref(false);
  284. const syncTodoBarFromMessages = () => {
  285. for (let i = messages.value.length - 1; i >= 0; i--) {
  286. const msg = messages.value[i];
  287. if (msg.type === 'ai' && msg.thinkingSteps) {
  288. for (let j = msg.thinkingSteps.length - 1; j >= 0; j--) {
  289. const step = msg.thinkingSteps[j];
  290. if (step.type === 'updated_todo_list' && step.todos) {
  291. currentTodos.value = [...step.todos];
  292. showTodoBar.value = true;
  293. return;
  294. }
  295. }
  296. }
  297. }
  298. showTodoBar.value = false;
  299. currentTodos.value = [];
  300. };
  301. const panelCollapsed = ref(false);
  302. const togglePanel = () => {
  303. panelCollapsed.value = !panelCollapsed.value;
  304. };
  305. const toggleSidePanel = (panel: 'skill' | 'schedules' | 'sub-agents') => {
  306. if (activePanel.value === panel) {
  307. activePanel.value = 'chat';
  308. } else {
  309. activePanel.value = panel;
  310. }
  311. };
  312. // Keep backward-compatible aliases
  313. const toggleSkillPanel = () => toggleSidePanel('skill');
  314. const toggleSchedulePanel = () => toggleSidePanel('schedules');
  315. const toggleSubAgentPanel = () => toggleSidePanel('sub-agents');
  316. const handleOpenScheduleSession = async (sessionId: string, prompt?: string) => {
  317. activePanel.value = 'chat';
  318. await fetchSessionList();
  319. await fetchScheduleListForDetail();
  320. const existing = taskList.value.find((t) => t.sessionId === sessionId);
  321. if (existing) {
  322. await switchTask(existing.id);
  323. } else {
  324. const newTask: Task = {
  325. id: sessionId,
  326. name: '定时任务',
  327. sessionId,
  328. messages: [],
  329. attachedFiles: [],
  330. };
  331. taskList.value.unshift(newTask);
  332. historyLoadedTasks.delete(sessionId);
  333. await switchTask(newTask.id);
  334. }
  335. // 如果有 prompt,自动发送消息
  336. if (prompt) {
  337. inputMessage.value = prompt;
  338. await nextTick();
  339. await handleSendMessage();
  340. }
  341. };
  342. const schedulePanelRef = ref();
  343. const handleScheduleDeleted = () => {
  344. const task = currentTask.value;
  345. if (task?.rightPanels) {
  346. const tab = task.rightPanels.tabs.find((t) => t.type === 'schedule');
  347. if (tab) removeTab(task.rightPanels, tab.id);
  348. }
  349. fetchScheduleListForDetail();
  350. schedulePanelRef.value?.fetchScheduleList?.();
  351. };
  352. const handleScheduleUpdated = async () => {
  353. await fetchScheduleListForDetail();
  354. // 同步标签内任务对象为最新数据(编辑/启停后)
  355. const task = currentTask.value;
  356. const tab = task?.rightPanels?.tabs.find((t) => t.type === 'schedule');
  357. if (tab?.type === 'schedule') {
  358. const fresh = scheduleListForDetail.value.find((s: any) => s.id === tab.task.id);
  359. if (fresh) tab.task = fresh;
  360. }
  361. schedulePanelRef.value?.fetchScheduleList?.();
  362. };
  363. // 标题保存(由 ChatHeader 子组件触发,父组件负责 API 调用和状态更新)
  364. const handleSaveTitle = async (newTitle: string) => {
  365. if (!currentTask.value?.sessionId) return;
  366. try {
  367. await editSessionTitle(currentTask.value.sessionId, newTitle);
  368. currentTask.value.name = newTitle;
  369. message.success('标题修改成功');
  370. } catch {
  371. message.error('标题修改失败');
  372. }
  373. };
  374. const isFullscreen = ref(!!props.defaultFullscreen);
  375. // 响应式视口宽度,用于计算 modal 最大宽度不超过屏幕
  376. const viewportWidth = ref(window.innerWidth);
  377. const onResize = () => {
  378. viewportWidth.value = window.innerWidth;
  379. };
  380. window.addEventListener('resize', onResize);
  381. const currentTask = computed(() => taskList.value.find((t) => t.id === currentTaskId.value));
  382. const currentRightPanels = computed<RightPanelState>(() => {
  383. const task = currentTask.value;
  384. return task?.rightPanels || { tabs: [], activeTabId: null };
  385. });
  386. // 是否有右侧辅助面板(标签页容器)与 chat-panel 并列显示
  387. const hasRightPanel = computed(() => {
  388. if (activePanel.value !== 'chat') return false;
  389. return currentRightPanels.value.tabs.length > 0;
  390. });
  391. // 面板离开动画标记:确保 modal 在面板退出动画结束后才收缩宽度
  392. const isPanelLeaving = ref(false);
  393. const modalShouldExpand = computed(() => hasRightPanel.value || isPanelLeaving.value);
  394. // modal 宽度:全屏100vw / 有右侧面板时1600px(不超视口)/ 默认1400px
  395. const modalWidth = computed(() => {
  396. if (isFullscreen.value) return '100vw';
  397. if (modalShouldExpand.value) return Math.min(1600, viewportWidth.value);
  398. return 1400;
  399. });
  400. // 右侧面板离开动画结束后,允许 modal 宽度收缩
  401. const onPanelLeaveEnd = () => {
  402. isPanelLeaving.value = false;
  403. };
  404. // 监听右侧面板从有到无,标记正在离开状态,防止 modal 宽度提前收缩
  405. watch(hasRightPanel, (newVal, oldVal) => {
  406. if (oldVal && !newVal) {
  407. isPanelLeaving.value = true;
  408. }
  409. });
  410. // 全屏切换,附带缩放动画效果
  411. const toggleFullscreen = () => {
  412. const enteringFs = !isFullscreen.value;
  413. isFullscreen.value = enteringFs;
  414. nextTick(() => {
  415. // 给 modal-content 添加缩放动画类,动画结束后自动移除
  416. const content = document.querySelector<HTMLElement>('.ai-assistant-modal .zxm-modal-content');
  417. if (content) {
  418. const animClass = enteringFs ? 'modal-zoom-in-anim' : 'modal-zoom-out-anim';
  419. content.classList.remove('modal-zoom-in-anim', 'modal-zoom-out-anim');
  420. void content.offsetWidth; // 强制重排,确保动画重新触发
  421. content.classList.add(animClass);
  422. content.addEventListener('animationend', () => content.classList.remove(animClass), { once: true });
  423. }
  424. applyWrapStyles(isFullscreen.value);
  425. draggedEl = null;
  426. if (!isFullscreen.value) {
  427. centerModal();
  428. }
  429. });
  430. };
  431. const inputMessage = ref('');
  432. const selectedSessions = ref<Array<{ id: string; name: string }>>([]);
  433. const selectedSkill = ref<{ name: string; display_name: string } | null>(null);
  434. // 按任务维度的状态存储
  435. const taskPendingApprovals = ref<Map<string, { sessionId: string; threadId: string }>>(new Map());
  436. // loading 和 streaming 共享同一个计算属性,基于当前任务的 isStreaming 状态
  437. const loading = computed(() => {
  438. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  439. return currentTask?.isStreaming ?? false;
  440. });
  441. const streaming = loading;
  442. // 获取当前任务的待审批状态
  443. const currentPendingApproval = computed(() => {
  444. return taskPendingApprovals.value.get(currentTaskId.value);
  445. });
  446. // Non-reactive Map for AbortControllers - only used imperatively, no need for Vue reactivity
  447. const taskAbortControllers = new Map<string, AbortController>();
  448. // 设置任务的AbortController
  449. const setTaskAbortController = (taskId: string, controller: AbortController | null) => {
  450. if (controller) {
  451. taskAbortControllers.set(taskId, controller);
  452. } else {
  453. taskAbortControllers.delete(taskId);
  454. }
  455. };
  456. // 设置任务的审批状态
  457. const setTaskPendingApproval = (taskId: string, sessionId: string, threadId: string) => {
  458. const map = new Map(taskPendingApprovals.value);
  459. map.set(taskId, { sessionId, threadId });
  460. taskPendingApprovals.value = map;
  461. };
  462. // 清除任务的审批状态
  463. const clearTaskPendingApproval = (taskId: string) => {
  464. const map = new Map(taskPendingApprovals.value);
  465. map.delete(taskId);
  466. taskPendingApprovals.value = map;
  467. };
  468. // 停止指定任务的流式传输
  469. const stopTaskStreaming = (taskId: string) => {
  470. const controller = taskAbortControllers.get(taskId);
  471. controller?.abort();
  472. };
  473. const stopStreaming = () => {
  474. stopTaskStreaming(currentTaskId.value);
  475. };
  476. const getCurrentSessionId = (): string => {
  477. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  478. return currentTask?.sessionId || '';
  479. };
  480. // Non-reactive lookup cache - Vue 3 does not track Set mutations on ref<Set>
  481. const historyLoadedTasks = new Set<string>();
  482. const setCurrentSessionId = (sessionId: string) => {
  483. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  484. if (currentTask && currentTask.id !== sessionId) {
  485. taskList.value = taskList.value.filter((t) => t.id !== sessionId);
  486. currentTask.id = sessionId;
  487. currentTask.sessionId = sessionId;
  488. currentTaskId.value = sessionId;
  489. historyLoadedTasks.add(sessionId);
  490. }
  491. };
  492. const switchTask = async (taskId: string) => {
  493. activePanel.value = 'chat';
  494. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  495. if (currentTask) {
  496. currentTask.messages = [...messages.value];
  497. }
  498. currentTaskId.value = taskId;
  499. const newTask = taskList.value.find((t) => t.id === taskId);
  500. if (!newTask) return;
  501. inputMessage.value = '';
  502. pendingFile.value = null;
  503. showFileList.value = false;
  504. if (newTask.sessionId && !historyLoadedTasks.has(taskId)) {
  505. if (newTask.isStreaming) return; // 新任务正在流式中,无需加载历史
  506. try {
  507. const res = await getDetail(newTask.sessionId);
  508. const messages = res?.messages || (Array.isArray(res) ? res : res?.data);
  509. if (Array.isArray(messages)) {
  510. newTask.messages = transformHistoryToMessages(messages);
  511. }
  512. historyLoadedTasks.add(taskId);
  513. } catch (error) {
  514. console.error('加载历史会话失败:', error);
  515. }
  516. }
  517. if (newTask.sessionId) {
  518. fetchContext(newTask.sessionId);
  519. fetchSessionMode(newTask.sessionId);
  520. } else {
  521. contextUsed.value = 0;
  522. contextPercent.value = 0;
  523. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  524. editMode.value = 'full';
  525. }
  526. messages.value = newTask.messages && newTask.messages.length > 0 ? [...newTask.messages] : getDefaultMessages();
  527. syncTodoBarFromMessages();
  528. // 切换任务时检测是否为定时任务会话:自动打开/关闭定时任务详情标签
  529. const scheduleItem = newTask.sessionId ? scheduleListForDetail.value.find((s: any) => s.feedback_session_id === newTask.sessionId) : undefined;
  530. const panelState = getPanelState(newTask);
  531. const existingScheduleTab = panelState.tabs.find((t) => t.type === 'schedule');
  532. if (scheduleItem) {
  533. if (existingScheduleTab) {
  534. panelState.activeTabId = existingScheduleTab.id;
  535. } else {
  536. panelState.tabs.push({ id: 'schedule', type: 'schedule', title: scheduleItem.name || '定时任务', task: scheduleItem });
  537. panelState.activeTabId = 'schedule';
  538. }
  539. } else if (existingScheduleTab) {
  540. removeTab(panelState, existingScheduleTab.id);
  541. }
  542. await nextTick();
  543. chatMessagesRef.value?.forceScrollToBottom();
  544. };
  545. const createNewTask = () => {
  546. const existingBlank = taskList.value.find((t) => !t.sessionId && t.messages.length === 0);
  547. if (existingBlank) {
  548. switchTask(existingBlank.id);
  549. return;
  550. }
  551. const newTask: Task = {
  552. id: `task-${Date.now()}`,
  553. name: '新任务',
  554. sessionId: '',
  555. messages: getDefaultMessages(),
  556. attachedFiles: [],
  557. };
  558. contextUsed.value = 0;
  559. contextPercent.value = 0;
  560. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  561. editMode.value = 'full';
  562. taskList.value.unshift(newTask);
  563. switchTask(newTask.id);
  564. };
  565. const handlePinTask = async (task: Task) => {
  566. if (!task.sessionId) {
  567. message.warning('请先发送消息后再置顶');
  568. return;
  569. }
  570. try {
  571. await pinSession(task.sessionId);
  572. await fetchSessionList();
  573. } catch {
  574. message.error('置顶操作失败');
  575. }
  576. };
  577. const handleThinkLevelChange = async (levelKey: string) => {
  578. try {
  579. await switchThinking(levelKey);
  580. } catch {
  581. message.error('切换思考级别失败');
  582. }
  583. };
  584. const handleUpdateSelectedSessions = (sessions: Array<{ id: string; name: string }>) => {
  585. selectedSessions.value = sessions;
  586. };
  587. const handleUpdateSelectedSkill = (skill: { name: string; display_name: string } | null) => {
  588. selectedSkill.value = skill;
  589. };
  590. const getSkillRefIconUrl = () => {
  591. const val = getComputedStyle(document.documentElement).getPropertyValue('--img-chat-options-skill-icon').trim();
  592. return val.replace(/^url\(["']?/, '').replace(/["']?\)$/, '');
  593. };
  594. const getSessionRefIconUrl = () => {
  595. const val = getComputedStyle(document.documentElement).getPropertyValue('--img-chat-popup-session-icon').trim();
  596. return val.replace(/^url\(["']?/, '').replace(/["']?\)$/, '');
  597. };
  598. const handleEditModeChange = async (modeKey: string) => {
  599. editMode.value = modeKey;
  600. const sessionId = getCurrentSessionId();
  601. if (!sessionId) return;
  602. try {
  603. await putSessionMode(sessionId, modeKey);
  604. } catch {
  605. message.error('切换模式失败');
  606. }
  607. };
  608. const findPendingApprovalTask = (): { taskId: string; approval: { sessionId: string; threadId?: string } } | null => {
  609. // 优先用当前任务 ID 查找
  610. let approval = currentPendingApproval.value;
  611. if (approval) return { taskId: currentTaskId.value, approval };
  612. // 遍历所有审批(可能任务 ID 已变,用 sessionId 做回退匹配)
  613. for (const [taskId, a] of taskPendingApprovals.value.entries()) {
  614. return { taskId, approval: a };
  615. }
  616. return null;
  617. };
  618. const handleAskUserSubmit = async (answers: string[]) => {
  619. // 防重复提交:如果当前任务正在流式中,忽略
  620. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  621. if (currentTask?.isStreaming) return;
  622. const found = findPendingApprovalTask();
  623. // 优先从 taskPendingApprovals 获取,若被清除则从消息的 pendingApprovalData 回退
  624. let sessionId = found?.approval.sessionId;
  625. let threadId = found?.approval.threadId;
  626. const foundTaskId = found?.taskId;
  627. // 查找任务:优先用 foundTaskId,回退到 currentTaskId
  628. let task = foundTaskId ? taskList.value.find((t) => t.id === foundTaskId) : null;
  629. if (!task) task = taskList.value.find((t) => t.id === currentTaskId.value);
  630. if (!task) return;
  631. // 切换到目标任务(如果不在当前视图)
  632. if (task.id !== currentTaskId.value) {
  633. await switchTask(task.id);
  634. }
  635. // 使用正确的消息数组:当前视图用 messages.value,否则用 task.messages
  636. const isViewingTask = currentTaskId.value === task.id;
  637. const sourceArr = isViewingTask ? messages.value : task.messages;
  638. const lastMsg = sourceArr[sourceArr.length - 1];
  639. if (!lastMsg || !lastMsg.isPendingApproval) return;
  640. // 若 taskPendingApprovals 已被清除,从消息的 pendingApprovalData 回退取值
  641. if (!sessionId && lastMsg.pendingApprovalData) {
  642. sessionId = lastMsg.pendingApprovalData.sessionId;
  643. threadId = lastMsg.pendingApprovalData.threadId;
  644. }
  645. if (!sessionId) return;
  646. lastMsg.isPendingApproval = false;
  647. lastMsg.pendingApprovalData = undefined;
  648. lastMsg.isLoading = true;
  649. lastMsg.generateStartTime = Date.now();
  650. const aiMsgIndex = sourceArr.length - 1;
  651. // 强制触发 Vue 响应式更新
  652. if (isViewingTask) {
  653. messages.value = [...sourceArr];
  654. }
  655. task.messages = [...sourceArr];
  656. task.isStreaming = true;
  657. showTodoBar.value = false;
  658. currentTodos.value = [];
  659. const controller = new AbortController();
  660. setTaskAbortController(task.id, controller);
  661. try {
  662. const result = await chatResumeStream(
  663. {
  664. session_id: sessionId,
  665. thread_id: threadId || undefined,
  666. status: 'answered',
  667. answers,
  668. signal: controller.signal,
  669. },
  670. (data: SseEvent) => {
  671. parseSSEData(data, aiMsgIndex, task.id);
  672. if (currentTaskId.value === task.id) scrollToBottomThrottled();
  673. }
  674. );
  675. if (result.session_id) {
  676. setCurrentSessionId(result.session_id);
  677. }
  678. } catch (error) {
  679. if ((error as Error)?.name === 'AbortError') {
  680. lastMsg.isLoading = false;
  681. lastMsg.durationMs = (lastMsg.baseDurationMs || 0) + (lastMsg.generateStartTime ? Date.now() - lastMsg.generateStartTime : 0);
  682. if (!lastMsg.content) {
  683. lastMsg.content = '已停止生成。';
  684. }
  685. } else {
  686. console.error('提交答案失败:', error);
  687. const isStreamError = error instanceof StreamError;
  688. message.error(isStreamError ? error.message : '提交失败,请重试');
  689. if (isStreamError) fetchTodayUsage();
  690. lastMsg.isLoading = false;
  691. lastMsg.durationMs = (lastMsg.baseDurationMs || 0) + (lastMsg.generateStartTime ? Date.now() - lastMsg.generateStartTime : 0);
  692. if (!lastMsg.content) {
  693. lastMsg.content = isStreamError ? error.message : '抱歉,提交请求失败,请稍后重试。';
  694. }
  695. }
  696. } finally {
  697. setTaskAbortController(task.id, null);
  698. task.isStreaming = false;
  699. // 仅当消息不再处于审批状态时才清除(避免 resume 流返回新 interrupt 被误清)
  700. if (!lastMsg.isPendingApproval) {
  701. clearTaskPendingApproval(task.id);
  702. }
  703. if (currentTaskId.value === task.id) {
  704. await scrollToBottom();
  705. }
  706. }
  707. };
  708. const handleAskUserCancel = async () => {
  709. // 防重复操作:如果当前任务正在流式中,忽略
  710. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  711. if (currentTask?.isStreaming) return;
  712. const found = findPendingApprovalTask();
  713. // 优先从 taskPendingApprovals 获取,若被清除则从消息的 pendingApprovalData 回退
  714. let sessionId = found?.approval.sessionId;
  715. let threadId = found?.approval.threadId;
  716. const foundTaskId = found?.taskId;
  717. // 查找任务:优先用 foundTaskId,回退到 currentTaskId
  718. let task = foundTaskId ? taskList.value.find((t) => t.id === foundTaskId) : null;
  719. if (!task) task = taskList.value.find((t) => t.id === currentTaskId.value);
  720. if (!task) return;
  721. // 切换到目标任务(如果不在当前视图)
  722. if (task.id !== currentTaskId.value) {
  723. await switchTask(task.id);
  724. }
  725. // 使用正确的消息数组
  726. const isViewingTask = currentTaskId.value === task.id;
  727. const sourceArr = isViewingTask ? messages.value : task.messages;
  728. const lastMsg = sourceArr[sourceArr.length - 1];
  729. if (!lastMsg || !lastMsg.isPendingApproval) return;
  730. // 若 taskPendingApprovals 已被清除,从消息的 pendingApprovalData 回退取值
  731. if (!sessionId && lastMsg.pendingApprovalData) {
  732. sessionId = lastMsg.pendingApprovalData.sessionId;
  733. threadId = lastMsg.pendingApprovalData.threadId;
  734. }
  735. if (!sessionId) return;
  736. // 冻结累计耗时到 durationMs,避免取消后计时消失
  737. lastMsg.durationMs = (lastMsg.baseDurationMs || 0) + (lastMsg.generateStartTime ? Date.now() - lastMsg.generateStartTime : 0);
  738. lastMsg.isPendingApproval = false;
  739. lastMsg.pendingApprovalData = undefined;
  740. lastMsg.isLoading = false;
  741. lastMsg.content = (lastMsg.content ? lastMsg.content + '\n\n' : '') + '已取消提问。';
  742. task.messages = [...sourceArr];
  743. if (isViewingTask) {
  744. messages.value = task.messages;
  745. }
  746. clearTaskPendingApproval(task.id);
  747. try {
  748. await chatResumeStream(
  749. {
  750. session_id: sessionId,
  751. thread_id: threadId || undefined,
  752. status: 'cancelled',
  753. },
  754. () => {}
  755. );
  756. } catch (error) {
  757. console.error('取消操作失败:', error);
  758. }
  759. task.isStreaming = false;
  760. if (currentTaskId.value === task.id) {
  761. messages.value = task.messages;
  762. await scrollToBottom();
  763. }
  764. };
  765. const handleDeleteTask = (task: Task, _index: number) => {
  766. Modal.confirm({
  767. title: '提示',
  768. content: '是否删除该对话?',
  769. okText: '确认',
  770. cancelText: '取消',
  771. wrapClassName: 'delete-task-confirm-modal',
  772. onOk: async () => {
  773. try {
  774. if (task.sessionId) {
  775. await deleteSession(task.sessionId);
  776. }
  777. const realIndex = taskList.value.findIndex((t) => t.id === task.id);
  778. if (realIndex !== -1) {
  779. taskList.value.splice(realIndex, 1);
  780. }
  781. if (currentTaskId.value === task.id) {
  782. if (taskList.value.length > 0) {
  783. switchTask(taskList.value[0].id);
  784. } else {
  785. messages.value = [];
  786. currentTaskId.value = '';
  787. }
  788. }
  789. message.success('删除成功');
  790. } catch {
  791. message.error('删除失败');
  792. }
  793. },
  794. });
  795. };
  796. const getDefaultMessages = (): Message[] => {
  797. return [];
  798. };
  799. const normalizeLineBreaks = (str: string): string => {
  800. if (!str) return '';
  801. return str.replace(/\\n/g, '\n').replace(/\r\n/g, '\n');
  802. };
  803. const transformHistoryToMessages = (
  804. data: Array<{
  805. id?: number;
  806. role?: string;
  807. type?: string;
  808. content: string;
  809. created_at?: string;
  810. report_url?: string;
  811. report_filename?: string;
  812. citations?: any;
  813. }>
  814. ): Message[] => {
  815. const messages: Message[] = [];
  816. for (const item of data) {
  817. const normalizedContent = normalizeLineBreaks(item.content);
  818. const time = item.created_at ? dayjs(item.created_at).format('HH:mm') : '';
  819. const createdAt = item.created_at || '';
  820. // 新格式:role 字段 (user/assistant)
  821. if (item.role === 'user') {
  822. messages.push({ id: item.id, type: 'user', content: normalizedContent, time, createdAt });
  823. } else if (item.role === 'assistant') {
  824. const msg: Message = { id: item.id, type: 'ai', content: normalizedContent, time, createdAt };
  825. if (item.report_url && item.report_filename) {
  826. msg.downloadFiles = [{ url: item.report_url, filename: item.report_filename }];
  827. }
  828. if (item.citations) {
  829. // 历史接口返回 citations 为扁平数组,SSE 事件返回 { items, model_only },统一归一化
  830. const raw = item.citations;
  831. if (Array.isArray(raw)) {
  832. msg.citations = { items: raw, model_only: raw.length === 0 };
  833. } else {
  834. msg.citations = raw;
  835. }
  836. }
  837. messages.push(msg);
  838. }
  839. // 兼容旧格式:type 字段
  840. else if (item.type === 'user_message') {
  841. messages.push({ id: item.id, type: 'user', content: normalizedContent, time, createdAt });
  842. } else if (item.type === 'model_thinking') {
  843. const lastAiMsg = messages[messages.length - 1];
  844. if (lastAiMsg && lastAiMsg.type === 'ai') {
  845. lastAiMsg.content += normalizedContent;
  846. lastAiMsg.content = lastAiMsg.content.replace(/\|\|\|SPLIT_CONTENT\|\|\|/g, '');
  847. } else {
  848. messages.push({ type: 'ai', content: normalizedContent, time, createdAt });
  849. }
  850. }
  851. }
  852. return messages;
  853. };
  854. const triggerFileUpload = () => {
  855. chatInputRef.value?.fileInputRef?.click();
  856. };
  857. const handleFileUpload = async (event: Event) => {
  858. const target = event.target as HTMLInputElement;
  859. const file = target.files?.[0];
  860. if (!file) return;
  861. if (isVideoFile(file.name) || isAudioFile(file.name)) {
  862. message.warning('不支持上传音频和视频文件');
  863. target.value = '';
  864. return;
  865. }
  866. try {
  867. const newFile: AttachedFile = {
  868. id: `file-${Date.now()}`,
  869. name: file.name,
  870. size: file.size,
  871. type: file.type,
  872. uploadTime: dayjs().format('YYYY-MM-DD HH:mm'),
  873. originalFile: file,
  874. };
  875. // Abort previous FileReader if still in progress
  876. if (activeFileReader.value) {
  877. activeFileReader.value.abort();
  878. activeFileReader.value = null;
  879. }
  880. const reader = new FileReader();
  881. activeFileReader.value = reader;
  882. reader.onload = (e) => {
  883. activeFileReader.value = null;
  884. if (isTextFile(file.name) || isCsvFile(file.name)) {
  885. newFile.content = e.target?.result as string;
  886. } else if (isWordFile(file.name) || isExcelFile(file.name)) {
  887. newFile.arrayBuffer = e.target?.result as ArrayBuffer;
  888. } else {
  889. newFile.preview = e.target?.result as string;
  890. }
  891. };
  892. if (isTextFile(file.name) || isCsvFile(file.name)) {
  893. reader.readAsText(file);
  894. } else if (isWordFile(file.name) || isExcelFile(file.name)) {
  895. reader.readAsArrayBuffer(file);
  896. } else {
  897. reader.readAsDataURL(file);
  898. }
  899. pendingFile.value = newFile;
  900. message.success(`文件 "${file.name}" 已添加,点击发送按钮提交`);
  901. } catch (error) {
  902. console.error('文件处理失败:', error);
  903. message.error('文件处理失败,请重试');
  904. }
  905. target.value = '';
  906. };
  907. const removePendingFile = () => {
  908. pendingFile.value = null;
  909. };
  910. const openFileTab = (file: AttachedFile, editable: boolean) => {
  911. const task = currentTask.value;
  912. if (!task) return;
  913. const state = getPanelState(task);
  914. const existing = state.tabs.find((t) => t.type === 'file' && t.file.id === file.id);
  915. if (existing) {
  916. // 编辑入口可升级已有标签为可编辑;预览入口不降级
  917. if (editable) existing.editable = true;
  918. state.activeTabId = existing.id;
  919. return;
  920. }
  921. openTab({ id: nextTabId(), type: 'file', title: file.name, file, editable });
  922. };
  923. const handleAgentDetailClick = (data: AgentDetailData) => {
  924. const task = currentTask.value;
  925. if (!task) return;
  926. const state = getPanelState(task);
  927. const existing = state.tabs.find(
  928. (t) => t.type === 'agent' && t.messageIndex === data.messageIndex && (t.agentId || '') === (data.agentId || '') && t.agent === data.agent
  929. );
  930. if (existing) {
  931. if (state.activeTabId === existing.id) {
  932. // 保持原交互:再次点击已激活的 agent 则关闭
  933. removeTab(state, existing.id);
  934. } else {
  935. state.activeTabId = existing.id;
  936. }
  937. return;
  938. }
  939. openTab({
  940. id: nextTabId(),
  941. type: 'agent',
  942. title: data.agent,
  943. messageIndex: data.messageIndex,
  944. agent: data.agent,
  945. agentId: data.agentId,
  946. });
  947. };
  948. // 删除单条消息:先删数据库行,后端再清空该会话内存线程,下轮从数据库重建上下文
  949. const handleDeleteMessage = (msg: Message) => {
  950. if (!msg.id) return;
  951. Modal.confirm({
  952. title: '提示',
  953. content: '删除后该消息将不再进入模型上下文,是否继续?',
  954. okText: '确认',
  955. cancelText: '取消',
  956. wrapClassName: 'delete-task-confirm-modal',
  957. onOk: async () => {
  958. try {
  959. await deleteMessage(msg.id!);
  960. message.success('消息已删除');
  961. messages.value = messages.value.filter((m) => m !== msg);
  962. const task = currentTask.value;
  963. if (task) {
  964. task.messages = task.messages.filter((m) => m !== msg);
  965. }
  966. } catch {
  967. message.error('删除失败');
  968. }
  969. },
  970. });
  971. };
  972. // 在右侧面板新建标签页展示 Markdown 代码块渲染效果(相同内容复用同一标签)
  973. const openMarkdownPreviewTab = (payload: { title: string; content: string }) => {
  974. let hash = 0;
  975. for (let i = 0; i < payload.content.length; i++) {
  976. hash = (hash * 31 + payload.content.charCodeAt(i)) | 0;
  977. }
  978. openFileTab(
  979. {
  980. id: `md-preview-${hash}`,
  981. name: `${payload.title}.md`,
  982. size: payload.content.length,
  983. type: 'text/markdown',
  984. content: payload.content,
  985. uploadTime: '',
  986. },
  987. false
  988. );
  989. };
  990. const openFilePreview = (file: AttachedFile) => {
  991. openFileTab(file, false);
  992. const msgIndex = messages.value.findIndex((m) => m.attachedFile?.id === file.id);
  993. if (msgIndex !== -1) {
  994. nextTick(() => {
  995. const messageElements = chatMessagesRef.value?.messagesRef?.querySelectorAll('.message-wrapper');
  996. if (messageElements && messageElements[msgIndex]) {
  997. (messageElements[msgIndex] as HTMLElement).scrollIntoView({
  998. behavior: 'smooth',
  999. block: 'center',
  1000. });
  1001. }
  1002. });
  1003. }
  1004. };
  1005. const getCurrentTaskFiles = (): AttachedFile[] => {
  1006. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  1007. return currentTask?.attachedFiles || [];
  1008. };
  1009. // 右侧辅助面板标签页状态(按任务维度保存,切换任务自动恢复)
  1010. let tabSeq = 0;
  1011. const nextTabId = () => `panel-${Date.now()}-${tabSeq++}`;
  1012. const getPanelState = (task: Task): RightPanelState => {
  1013. if (!task.rightPanels) {
  1014. task.rightPanels = { tabs: [], activeTabId: null };
  1015. }
  1016. return task.rightPanels;
  1017. };
  1018. const openTab = (tab: RightPanelTab) => {
  1019. const task = currentTask.value;
  1020. if (!task) return;
  1021. const state = getPanelState(task);
  1022. state.tabs.push(tab);
  1023. state.activeTabId = tab.id;
  1024. };
  1025. const activateTab = (tabId: string) => {
  1026. const task = currentTask.value;
  1027. if (!task?.rightPanels) return;
  1028. if (task.rightPanels.tabs.some((t) => t.id === tabId)) {
  1029. task.rightPanels.activeTabId = tabId;
  1030. }
  1031. };
  1032. const removeTab = (state: RightPanelState, tabId: string) => {
  1033. const idx = state.tabs.findIndex((t) => t.id === tabId);
  1034. if (idx === -1) return;
  1035. state.tabs.splice(idx, 1);
  1036. if (state.activeTabId === tabId) {
  1037. state.activeTabId = state.tabs.length ? (state.tabs[idx] || state.tabs[idx - 1]).id : null;
  1038. }
  1039. };
  1040. const closeTab = (tabId: string) => {
  1041. const task = currentTask.value;
  1042. if (!task?.rightPanels) return;
  1043. removeTab(task.rightPanels, tabId);
  1044. };
  1045. const currentWordUrl = computed(() => {
  1046. return currentTask.value?.wordUrl || '';
  1047. });
  1048. const currentTaskIndex = computed(() => taskList.value.findIndex((t) => t.id === currentTaskId.value));
  1049. const canGoPrev = computed(() => currentTaskIndex.value > 0);
  1050. const canGoNext = computed(() => currentTaskIndex.value >= 0 && currentTaskIndex.value < taskList.value.length - 1);
  1051. const goToPrev = () => {
  1052. if (!canGoPrev.value) return;
  1053. const prevTask = taskList.value[currentTaskIndex.value - 1];
  1054. if (prevTask) switchTask(prevTask.id);
  1055. };
  1056. const goToNext = () => {
  1057. if (!canGoNext.value) return;
  1058. const nextTask = taskList.value[currentTaskIndex.value + 1];
  1059. if (nextTask) switchTask(nextTask.id);
  1060. };
  1061. const downloadWordFile = (url: string) => {
  1062. if (!url) return;
  1063. const a = document.createElement('a');
  1064. a.href = url;
  1065. a.download = '';
  1066. a.target = '_blank';
  1067. document.body.appendChild(a);
  1068. a.click();
  1069. document.body.removeChild(a);
  1070. };
  1071. const downloadWordReport = () => downloadWordFile(currentWordUrl.value);
  1072. const handleOpenFilePreview = (file: AttachedFile) => {
  1073. openFileTab(file, true);
  1074. };
  1075. const handleSaveSuccess = (content: string) => {
  1076. const task = currentTask.value;
  1077. const tab = task?.rightPanels?.tabs.find((t) => t.id === task.rightPanels?.activeTabId);
  1078. if (tab?.type === 'file') {
  1079. tab.file = { ...tab.file, content };
  1080. }
  1081. };
  1082. const handleSendMessage = async () => {
  1083. const hasText = inputMessage.value.trim();
  1084. const hasFile = pendingFile.value;
  1085. if (!hasText) {
  1086. message.warning('请输入消息内容');
  1087. return;
  1088. }
  1089. if (loading.value) return;
  1090. if (currentPendingApproval.value) {
  1091. message.warning('请先审批执行计划');
  1092. return;
  1093. }
  1094. const sessionPrefix = selectedSessions.value.length > 0 ? selectedSessions.value.map((s) => `#session:${s.id}`).join(' ') + ' ' : '';
  1095. const skillPrefix = selectedSkill.value ? `#skill:${selectedSkill.value.name} ` : '';
  1096. const userInput = skillPrefix + sessionPrefix + inputMessage.value.trim();
  1097. let displayContent = inputMessage.value.trim();
  1098. if (selectedSkill.value) {
  1099. const skillIconUrl = getSkillRefIconUrl();
  1100. displayContent = `[<img src="${skillIconUrl}" class="session-ref-icon" /> 技能:${selectedSkill.value.display_name}] ${displayContent}`;
  1101. }
  1102. if (selectedSessions.value.length > 0) {
  1103. const names = selectedSessions.value.map((s) => s.name).join('、');
  1104. const iconUrl = getSessionRefIconUrl();
  1105. displayContent = `[<img src="${iconUrl}" class="session-ref-icon" /> 引用 ${selectedSessions.value.length} 个会话:${names}] ${displayContent}`;
  1106. }
  1107. const fileToSend = pendingFile.value;
  1108. inputMessage.value = '';
  1109. pendingFile.value = null;
  1110. selectedSessions.value = [];
  1111. selectedSkill.value = null;
  1112. try {
  1113. await nextTick();
  1114. chatMessagesRef.value?.forceScrollToBottom();
  1115. if (hasFile) {
  1116. await sendWithAttachment(fileToSend!, userInput, displayContent);
  1117. } else {
  1118. await sendTextOnly(userInput, displayContent);
  1119. }
  1120. } catch (error) {
  1121. console.error('发送消息失败:', error);
  1122. const isStreamError = error instanceof StreamError;
  1123. const errText = isStreamError ? error.message : '发送失败,请重试';
  1124. message.error(errText);
  1125. if (isStreamError) fetchTodayUsage();
  1126. const lastMsg = messages.value[messages.value.length - 1];
  1127. if (lastMsg && lastMsg.type === 'ai' && lastMsg.isLoading) {
  1128. messages.value.pop();
  1129. }
  1130. const errorMsg: Message = {
  1131. type: 'ai',
  1132. content: isStreamError ? error.message : '抱歉,请求失败,请稍后重试。',
  1133. time: dayjs().format('HH:mm'),
  1134. };
  1135. messages.value.push(errorMsg);
  1136. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  1137. if (currentTask) {
  1138. currentTask.messages = [...messages.value];
  1139. }
  1140. } finally {
  1141. await scrollToBottom(true);
  1142. }
  1143. };
  1144. const extractAgentName = (toolName: string): string => {
  1145. const nameMap: Record<string, string> = {
  1146. form_review: '形式审查',
  1147. verify_coal_face_ventilation: '采煤工作面需风量计算核验',
  1148. verify_tunneling_face_ventilation: '掘进工作面需风量计算核验',
  1149. verify_chamber_ventilation: '硐室需风量计算核验',
  1150. verify_other_points_ventilation: '其他地点需风量计算核验',
  1151. check_data_by_gas_report: '瓦斯数据一致性审查',
  1152. check_data_by_face_design: '设计规程一致性审查',
  1153. check_data_by_vent_report: '测风报表一致性审查',
  1154. check_current_month_plan: '日期有效性审查',
  1155. get_key_translate: '计算参数对照',
  1156. calculate_ventilation: '需风量计算',
  1157. get_ventilation_data: '需风量查询',
  1158. recalculate_ventilation: '需风量重计算',
  1159. get_plan_required_wind: '需风量提取',
  1160. get_model_calculated_wind: '三维模型解算风量提取',
  1161. get_sensor_wind: '巷道监测风量提取',
  1162. merge_wind_by_location: '地点风量智能合并',
  1163. check_wind_compliance: '风量检查',
  1164. };
  1165. return nameMap[toolName] || nameMap[toolName.toLowerCase()] || '智能分析助手';
  1166. };
  1167. // 累积所有步骤,保留完整历史
  1168. const upsertStep = (steps: any[], step: any) => {
  1169. steps.push(step);
  1170. };
  1171. const fetchModelMsg = async () => {
  1172. try {
  1173. const res = await getModelMsg();
  1174. if (res?.thinking_level) {
  1175. thinkLevel.value = res.thinking_level;
  1176. }
  1177. } catch (e) {
  1178. console.error('获取模型信息失败:', e);
  1179. }
  1180. };
  1181. const fetchSessionMode = async (sessionId: string) => {
  1182. try {
  1183. const res = await getSessionMode(sessionId);
  1184. if (res?.mode) {
  1185. editMode.value = res.mode;
  1186. }
  1187. } catch (e) {
  1188. console.error('获取会话模式失败:', e);
  1189. }
  1190. };
  1191. const fetchContext = async (sessionId: string) => {
  1192. try {
  1193. const res = await getContext(sessionId);
  1194. contextUsed.value = res?.current_usage ?? 0;
  1195. contextMax.value = res?.total_limit ?? 0;
  1196. contextPercent.value = res?.usage_pct ?? 0;
  1197. contextBreakdown.value = res?.breakdown ?? { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  1198. } catch (e) {
  1199. console.error('获取上下文容量失败:', e);
  1200. contextUsed.value = 0;
  1201. contextMax.value = 0;
  1202. contextPercent.value = 0;
  1203. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  1204. }
  1205. };
  1206. const handleSSEMessage = (data: any, aiMsgIndex: number, taskId: string) => {
  1207. const streamingTask = taskList.value.find((t) => t.id === taskId);
  1208. if (!streamingTask) return;
  1209. // 当前正在查看流式任务时,新消息被 push 到 messages.value 而非 task.messages
  1210. // 所以需要从 messages.value 读取;否则从任务存储的 messages 读取
  1211. const isViewingTask = currentTaskId.value === taskId;
  1212. const sourceArr = isViewingTask ? messages.value : streamingTask.messages;
  1213. const aiMsg = sourceArr[aiMsgIndex];
  1214. if (!aiMsg) return;
  1215. const normalizedContent = normalizeLineBreaks(data.content || '');
  1216. // 初始化 thinkingSteps 数组
  1217. if (!aiMsg.thinkingSteps) {
  1218. aiMsg.thinkingSteps = [];
  1219. }
  1220. switch (data.type) {
  1221. // token 流式内容 - 直接拼接到消息内容
  1222. case 'token':
  1223. if (normalizedContent) {
  1224. if (data.source === 'subagent' && data.agent_id) {
  1225. // subagent 的输出内容归属到对应的 agent step
  1226. const targetStep = aiMsg.thinkingSteps!.findLast((s) => s.type === 'agent_start' && s.agentId === data.agent_id);
  1227. if (targetStep) {
  1228. targetStep.content = (targetStep.content || '') + normalizedContent;
  1229. }
  1230. } else {
  1231. // main 模型输出,保持原有逻辑
  1232. aiMsg.content += normalizedContent;
  1233. }
  1234. }
  1235. break;
  1236. // thinking / thinking_token - 模型思考过程内容
  1237. case 'thinking':
  1238. case 'thinking_token':
  1239. if (normalizedContent) {
  1240. if (data.source === 'subagent' && data.agent_id) {
  1241. // subagent 的思考内容归属到对应的 agent step
  1242. const targetStep = aiMsg.thinkingSteps!.findLast((s) => s.type === 'agent_start' && s.agentId === data.agent_id);
  1243. if (targetStep) {
  1244. targetStep.thinkingContent = (targetStep.thinkingContent || '') + normalizedContent;
  1245. }
  1246. } else {
  1247. // main 模型思考,保持原有逻辑
  1248. aiMsg.thinkingContent = (aiMsg.thinkingContent || '') + normalizedContent;
  1249. }
  1250. }
  1251. break;
  1252. // 系统进度消息 - 仅当 agent 不是 system 时才作为 thinking step
  1253. case 'progress': {
  1254. if (data.agent && data.agent !== 'system') {
  1255. upsertStep(aiMsg.thinkingSteps!, {
  1256. type: 'executing',
  1257. agent: data.cn_agent || data.agent,
  1258. agentId: data.agent_id,
  1259. message: data.message || '',
  1260. timestamp: Date.now(),
  1261. });
  1262. }
  1263. break;
  1264. }
  1265. // agent 开始处理
  1266. case 'agent_start': {
  1267. upsertStep(aiMsg.thinkingSteps!, {
  1268. type: 'agent_start',
  1269. agent: data.cn_agent || data.agent || '智能助手',
  1270. agentId: data.agent_id,
  1271. subagentType: data.subagent_type,
  1272. message: data.message || '开始处理...',
  1273. timestamp: Date.now(),
  1274. });
  1275. break;
  1276. }
  1277. // agent 任务列表更新(同一 agent 的 todos 更新已有条目,不重复添加)
  1278. case 'agent_todos':
  1279. case 'updated_todo_list': {
  1280. const agentName = data.cn_agent || data.agent || '智能助手';
  1281. const agentId = data.agent_id;
  1282. const existingIdx = aiMsg.thinkingSteps!.findIndex(
  1283. (s) => s.type === 'updated_todo_list' && (agentId ? s.agentId === agentId : s.agent === agentName)
  1284. );
  1285. if (existingIdx !== -1) {
  1286. aiMsg.thinkingSteps![existingIdx].todos = data.todos || [];
  1287. aiMsg.thinkingSteps![existingIdx].timestamp = Date.now();
  1288. } else {
  1289. aiMsg.thinkingSteps!.push({
  1290. type: 'updated_todo_list',
  1291. agent: agentName,
  1292. agentId,
  1293. todos: data.todos || [],
  1294. message: data.message || '任务进度已更新',
  1295. timestamp: Date.now(),
  1296. });
  1297. }
  1298. // todos 与任务绑定:仅当用户正在查看该任务时才更新进度条,避免流式期间切换/新建任务后串台
  1299. if (isViewingTask) {
  1300. currentTodos.value = [...(data.todos || [])];
  1301. showTodoBar.value = true;
  1302. }
  1303. break;
  1304. }
  1305. // agent 执行中(工具调用)
  1306. case 'agent_executing':
  1307. case 'executing': {
  1308. upsertStep(aiMsg.thinkingSteps!, {
  1309. type: 'executing',
  1310. agent: data.cn_agent || data.agent || '智能助手',
  1311. agentId: data.agent_id,
  1312. tool: (data.cn_tools || data.tools || []).join('、'),
  1313. message: data.message || '',
  1314. timestamp: Date.now(),
  1315. });
  1316. break;
  1317. }
  1318. // 工具结果
  1319. case 'agent_tool_result':
  1320. case 'tool_result': {
  1321. upsertStep(aiMsg.thinkingSteps!, {
  1322. type: 'tool_result',
  1323. agent: data.cn_agent || data.agent || '智能助手',
  1324. agentId: data.agent_id,
  1325. tool: data.cn_tool || data.tool || '',
  1326. message: data.message || '执行完成',
  1327. timestamp: Date.now(),
  1328. });
  1329. if (data.download_url) {
  1330. if (!aiMsg.downloadFiles) aiMsg.downloadFiles = [];
  1331. aiMsg.downloadFiles.push({ url: data.download_url, filename: data.filename || '文件' });
  1332. }
  1333. break;
  1334. }
  1335. // agent 完成
  1336. case 'agent_done': {
  1337. upsertStep(aiMsg.thinkingSteps!, {
  1338. type: 'agent_done',
  1339. agent: data.cn_agent || data.agent || '智能助手',
  1340. agentId: data.agent_id,
  1341. message: `${(data.message || '审查完成').replace(/(\d+ms)/g, '')}${data.duration_ms ? `(${(data.duration_ms / 1000).toFixed(0)}s)` : ''}${data.progress ? ` [${data.progress}]` : ''}`,
  1342. timestamp: Date.now(),
  1343. });
  1344. // 累加后端返回的各段耗时,并重置前端计时起点,避免重复计算已验证的时间段
  1345. if (data.duration_ms) {
  1346. aiMsg.baseDurationMs = (aiMsg.baseDurationMs || 0) + data.duration_ms;
  1347. aiMsg.generateStartTime = Date.now();
  1348. }
  1349. if (data.preview) {
  1350. aiMsg.content += data.preview;
  1351. }
  1352. break;
  1353. }
  1354. // 旧格式兼容
  1355. case 'model_thinking':
  1356. if (normalizedContent) {
  1357. aiMsg.content += normalizedContent;
  1358. aiMsg.content = aiMsg.content.replace(/\|\|\|SPLIT_CONTENT\|\|\|/g, '');
  1359. }
  1360. break;
  1361. case 'tool_select': {
  1362. upsertStep(aiMsg.thinkingSteps!, {
  1363. type: 'tool_call',
  1364. agent: data.cn_agent || extractAgentName(normalizedContent),
  1365. agentId: data.agent_id,
  1366. tool: normalizedContent,
  1367. message: `选择工具:${normalizedContent}`,
  1368. timestamp: Date.now(),
  1369. });
  1370. break;
  1371. }
  1372. case 'error':
  1373. upsertStep(aiMsg.thinkingSteps!, {
  1374. type: 'tool_result',
  1375. agent: data.cn_agent || '系统',
  1376. agentId: data.agent_id,
  1377. message: `❌ 执行失败:${normalizedContent}`,
  1378. timestamp: Date.now(),
  1379. });
  1380. aiMsg.isLoading = false;
  1381. streamingTask.isStreaming = false;
  1382. // 后端未返回耗时,冻结前端伪计时
  1383. aiMsg.durationMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1384. break;
  1385. case 'citations': {
  1386. aiMsg.citations = {
  1387. items: data.items || [],
  1388. model_only: data.model_only || false,
  1389. message: data.message,
  1390. };
  1391. break;
  1392. }
  1393. case 'word_download':
  1394. if (normalizedContent) {
  1395. aiMsg.wordDownloadUrl = normalizedContent;
  1396. streamingTask.wordUrl = normalizedContent;
  1397. }
  1398. break;
  1399. case 'done':
  1400. if (data.session_id) {
  1401. aiMsg.sessionId = data.session_id;
  1402. fetchContext(data.session_id);
  1403. }
  1404. // 对话结束后刷新今日用量
  1405. fetchTodayUsage();
  1406. aiMsg.durationMs = data.duration_ms
  1407. ? (aiMsg.baseDurationMs || 0) + data.duration_ms
  1408. : (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1409. aiMsg.isLoading = false;
  1410. streamingTask.isStreaming = false;
  1411. break;
  1412. case 'system':
  1413. if (normalizedContent) {
  1414. aiMsg.content += normalizedContent.replace(/\n/g, ' \n');
  1415. }
  1416. break;
  1417. case 'interrupt': {
  1418. // 后端各段耗时 + 前端当前段计时,吸收进 baseDurationMs 保证审批继续后计时连续
  1419. const elapsedMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1420. aiMsg.baseDurationMs = elapsedMs;
  1421. aiMsg.isLoading = false;
  1422. // 流已结束,等待用户回答;提交答案后 handleAskUserSubmit 会重新置为流式中
  1423. streamingTask.isStreaming = false;
  1424. aiMsg.isPendingApproval = true;
  1425. const interruptSessionId = data.session_id || streamingTask.sessionId;
  1426. aiMsg.pendingApprovalData = {
  1427. message: data.message || '智能体需要您回答一些问题以继续...',
  1428. sessionId: interruptSessionId,
  1429. threadId: data.thread_id,
  1430. interrupts: data.interrupts,
  1431. elapsedMs,
  1432. prevThinkingContent: aiMsg.thinkingContent,
  1433. plan: data.plan,
  1434. ask_user: data.ask_user,
  1435. answers: data.ask_user?.questions?.map(() => '') || [],
  1436. };
  1437. setTaskPendingApproval(taskId, interruptSessionId, data.thread_id || '');
  1438. // 直接初始化 ask_user 答案状态,不依赖 watch(避免任务切换/时序问题)
  1439. if (data.ask_user?.questions) {
  1440. nextTick(() => {
  1441. chatMessagesRef.value?.initAskUserAnswers(aiMsgIndex, data.ask_user!.questions);
  1442. });
  1443. }
  1444. break;
  1445. }
  1446. }
  1447. // 保存到流式任务的 messages,并同步 UI
  1448. // Always create a new array reference to trigger Vue reactivity
  1449. const updatedMessages = isViewingTask ? [...messages.value] : [...streamingTask.messages];
  1450. streamingTask.messages = updatedMessages;
  1451. if (isViewingTask) {
  1452. messages.value = updatedMessages;
  1453. }
  1454. };
  1455. const parseSSEData = (data: SseEvent, aiMsgIndex: number, taskId: string) => {
  1456. handleSSEMessage(data, aiMsgIndex, taskId);
  1457. };
  1458. const sendTextOnly = async (userInput: string, displayContent?: string) => {
  1459. const originTaskId = currentTaskId.value;
  1460. const now = dayjs();
  1461. const userMsg: Message = {
  1462. type: 'user',
  1463. content: displayContent || userInput,
  1464. time: now.format('HH:mm'),
  1465. createdAt: now.toISOString(),
  1466. };
  1467. messages.value.push(userMsg);
  1468. await nextTick();
  1469. chatMessagesRef.value?.forceScrollToBottom();
  1470. const aiMsgIndex = messages.value.length;
  1471. const aiMsg: Message = {
  1472. type: 'ai',
  1473. content: '',
  1474. time: now.format('HH:mm'),
  1475. createdAt: now.toISOString(),
  1476. isLoading: true,
  1477. thinkingSteps: [],
  1478. generateStartTime: Date.now(),
  1479. };
  1480. messages.value.push(aiMsg);
  1481. showTodoBar.value = false;
  1482. currentTodos.value = [];
  1483. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1484. if (originTask) originTask.isStreaming = true;
  1485. const controller = new AbortController();
  1486. setTaskAbortController(originTaskId, controller);
  1487. try {
  1488. const result = await unifiedStream(
  1489. {
  1490. message: userInput,
  1491. session_id: getCurrentSessionId() || undefined,
  1492. mode: editMode.value,
  1493. signal: controller.signal,
  1494. },
  1495. (data: SseEvent) => {
  1496. parseSSEData(data, aiMsgIndex, originTaskId);
  1497. if (currentTaskId.value === originTaskId) scrollToBottomThrottled();
  1498. }
  1499. );
  1500. if (result.session_id) {
  1501. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1502. if (originTask && !originTask.sessionId) {
  1503. originTask.sessionId = result.session_id;
  1504. // 流式期间若列表已用后端标题归并过该任务,则保留后端标题;否则用首条消息命名
  1505. if (originTask.pendingSessionId !== result.session_id) {
  1506. originTask.name = userInput.substring(0, 20) + (userInput.length > 20 ? '...' : '');
  1507. }
  1508. originTask.pendingSessionId = undefined;
  1509. if (originTask.id !== result.session_id) {
  1510. // 将 AbortController 从旧 ID 迁移到新 ID
  1511. const controller = taskAbortControllers.get(originTaskId);
  1512. if (controller) {
  1513. setTaskAbortController(originTaskId, null);
  1514. setTaskAbortController(result.session_id, controller);
  1515. }
  1516. taskList.value = taskList.value.filter((t) => t.id !== result.session_id);
  1517. originTask.id = result.session_id;
  1518. historyLoadedTasks.add(result.session_id);
  1519. // 迁移审批状态 key(任务 ID 变了,审批 Map 的 key 也要跟着变)
  1520. const approvalEntry = taskPendingApprovals.value.get(originTaskId);
  1521. if (approvalEntry) {
  1522. const map = new Map(taskPendingApprovals.value);
  1523. map.delete(originTaskId);
  1524. map.set(result.session_id, approvalEntry);
  1525. taskPendingApprovals.value = map;
  1526. }
  1527. }
  1528. if (currentTaskId.value === originTaskId) {
  1529. currentTaskId.value = result.session_id;
  1530. }
  1531. }
  1532. }
  1533. } catch (error) {
  1534. // 用户主动停止生成
  1535. if ((error as Error)?.name === 'AbortError') {
  1536. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1537. const arr = currentTaskId.value === originTaskId ? messages.value : originTask?.messages;
  1538. const aiMsg = arr?.[aiMsgIndex];
  1539. if (aiMsg) {
  1540. aiMsg.isLoading = false;
  1541. // 后端未返回耗时,冻结前端伪计时
  1542. aiMsg.durationMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1543. if (!aiMsg.content) {
  1544. aiMsg.content = '已停止生成。';
  1545. }
  1546. }
  1547. if (originTask && currentTaskId.value !== originTaskId) {
  1548. originTask.messages = [...(arr || [])];
  1549. }
  1550. return;
  1551. }
  1552. throw error;
  1553. } finally {
  1554. // 任务在流结束时可能已被改名为后端 session_id,需要使用最终的 ID 清理状态
  1555. const finalTaskId = originTask?.id || originTaskId;
  1556. setTaskAbortController(finalTaskId, null);
  1557. if (originTask) originTask.isStreaming = false;
  1558. }
  1559. };
  1560. const sendWithAttachment = async (file: AttachedFile, userInput: string, displayContent?: string) => {
  1561. const originTaskId = currentTaskId.value;
  1562. let currentTask = taskList.value.find((t) => t.id === originTaskId);
  1563. if (currentTask) {
  1564. currentTask.attachedFiles.push(file);
  1565. } else {
  1566. throw new Error('未找到当前任务');
  1567. }
  1568. const now = dayjs();
  1569. const userMsg: Message = {
  1570. type: 'user',
  1571. content: displayContent || userInput || `上传了文件:${file.name}`,
  1572. time: now.format('HH:mm'),
  1573. createdAt: now.toISOString(),
  1574. attachedFile: file,
  1575. };
  1576. messages.value.push(userMsg);
  1577. await nextTick();
  1578. chatMessagesRef.value?.forceScrollToBottom();
  1579. const aiMsgIndex = messages.value.length;
  1580. const aiMsg: Message = {
  1581. type: 'ai',
  1582. content: '',
  1583. time: now.format('HH:mm'),
  1584. createdAt: now.toISOString(),
  1585. isLoading: true,
  1586. thinkingSteps: [],
  1587. generateStartTime: Date.now(),
  1588. };
  1589. messages.value.push(aiMsg);
  1590. showTodoBar.value = false;
  1591. currentTodos.value = [];
  1592. if (!file.originalFile) {
  1593. throw new Error('缺少原始文件对象');
  1594. }
  1595. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1596. if (originTask) originTask.isStreaming = true;
  1597. const controller = new AbortController();
  1598. setTaskAbortController(originTaskId, controller);
  1599. try {
  1600. const result = await reviewPdfStream(
  1601. {
  1602. file: file.originalFile!,
  1603. session_id: getCurrentSessionId() || undefined,
  1604. message: userInput || undefined,
  1605. mode: editMode.value,
  1606. signal: controller.signal,
  1607. },
  1608. (data: SseEvent) => {
  1609. parseSSEData(data, aiMsgIndex, originTaskId);
  1610. if (currentTaskId.value === originTaskId) scrollToBottomThrottled();
  1611. }
  1612. );
  1613. if (result.session_id) {
  1614. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1615. if (originTask && !originTask.sessionId) {
  1616. originTask.sessionId = result.session_id;
  1617. if (originTask.pendingSessionId !== result.session_id) {
  1618. const taskName = userInput || `文件:${file.name}`;
  1619. originTask.name = taskName.substring(0, 20) + (taskName.length > 20 ? '...' : '');
  1620. }
  1621. originTask.pendingSessionId = undefined;
  1622. if (originTask.id !== result.session_id) {
  1623. // 将 AbortController 从旧 ID 迁移到新 ID
  1624. const controller = taskAbortControllers.get(originTaskId);
  1625. if (controller) {
  1626. setTaskAbortController(originTaskId, null);
  1627. setTaskAbortController(result.session_id, controller);
  1628. }
  1629. taskList.value = taskList.value.filter((t) => t.id !== result.session_id);
  1630. originTask.id = result.session_id;
  1631. historyLoadedTasks.add(result.session_id);
  1632. // 迁移审批状态 key
  1633. const approvalEntry = taskPendingApprovals.value.get(originTaskId);
  1634. if (approvalEntry) {
  1635. const map = new Map(taskPendingApprovals.value);
  1636. map.delete(originTaskId);
  1637. map.set(result.session_id, approvalEntry);
  1638. taskPendingApprovals.value = map;
  1639. }
  1640. }
  1641. if (currentTaskId.value === originTaskId) {
  1642. currentTaskId.value = result.session_id;
  1643. }
  1644. }
  1645. }
  1646. } catch (error) {
  1647. // 用户主动停止生成
  1648. if ((error as Error)?.name === 'AbortError') {
  1649. const originTask = taskList.value.find((t) => t.id === originTaskId);
  1650. const arr = currentTaskId.value === originTaskId ? messages.value : originTask?.messages;
  1651. const aiMsg = arr?.[aiMsgIndex];
  1652. if (aiMsg) {
  1653. aiMsg.isLoading = false;
  1654. // 后端未返回耗时,冻结前端伪计时
  1655. aiMsg.durationMs = (aiMsg.baseDurationMs || 0) + (aiMsg.generateStartTime ? Date.now() - aiMsg.generateStartTime : 0);
  1656. if (!aiMsg.content) {
  1657. aiMsg.content = '已停止生成。';
  1658. }
  1659. }
  1660. if (originTask && currentTaskId.value !== originTaskId) {
  1661. originTask.messages = [...(arr || [])];
  1662. }
  1663. return;
  1664. }
  1665. throw error;
  1666. } finally {
  1667. // 任务在流结束时可能已被改名为后端 session_id,需要使用最终的 ID 清理状态
  1668. const finalTaskId = originTask?.id || originTaskId;
  1669. setTaskAbortController(finalTaskId, null);
  1670. if (originTask) originTask.isStreaming = false;
  1671. }
  1672. };
  1673. // Throttled version for SSE streaming (no await, uses rAF)
  1674. let scrollRafId: number | null = null;
  1675. const scrollToBottomThrottled = (force = false) => {
  1676. if (scrollRafId) cancelAnimationFrame(scrollRafId);
  1677. scrollRafId = requestAnimationFrame(async () => {
  1678. scrollRafId = null;
  1679. await nextTick();
  1680. if (!force && !chatMessagesRef.value?.isAtBottom) return;
  1681. const el = chatMessagesRef.value?.messagesRef;
  1682. if (el) {
  1683. el.scrollTop = el.scrollHeight - el.clientHeight;
  1684. }
  1685. });
  1686. };
  1687. // Async version for explicit await calls
  1688. const scrollToBottom = async (force = false) => {
  1689. await nextTick();
  1690. if (!force && !chatMessagesRef.value?.isAtBottom) return;
  1691. const el = chatMessagesRef.value?.messagesRef;
  1692. if (el) {
  1693. el.scrollTop = el.scrollHeight - el.clientHeight;
  1694. }
  1695. };
  1696. watch(
  1697. () => props.visible,
  1698. async (newVisible) => {
  1699. if (!newVisible) {
  1700. const currentTask = taskList.value.find((t) => t.id === currentTaskId.value);
  1701. if (currentTask) {
  1702. currentTask.messages = [...messages.value];
  1703. }
  1704. } else {
  1705. await fetchSessionList();
  1706. fetchModelMsg();
  1707. fetchScheduleListForDetail();
  1708. fetchTodayUsage();
  1709. // 去除重复的空白任务,只保留一个
  1710. taskList.value = taskList.value.filter((task, index) => {
  1711. if (task.sessionId) return true;
  1712. return index === taskList.value.findIndex((t) => !t.sessionId);
  1713. });
  1714. // 优先回到关闭前所在的任务(如流式中的新任务),否则默认选中第一条历史记录
  1715. const firstHistoryTask = taskList.value.find((t) => t.sessionId);
  1716. const prevTask = taskList.value.find((t) => t.id === currentTaskId.value);
  1717. let targetTask: Task;
  1718. if (prevTask) {
  1719. targetTask = prevTask;
  1720. } else if (firstHistoryTask) {
  1721. targetTask = firstHistoryTask;
  1722. } else {
  1723. // 没有历史记录时才创建空白新任务
  1724. targetTask = {
  1725. id: `task-${Date.now()}`,
  1726. name: '新任务',
  1727. sessionId: '',
  1728. messages: getDefaultMessages(),
  1729. attachedFiles: [],
  1730. };
  1731. taskList.value.unshift(targetTask);
  1732. }
  1733. currentTaskId.value = targetTask.id;
  1734. // 如果是历史任务,加载其消息
  1735. if (targetTask.sessionId && !historyLoadedTasks.has(targetTask.id)) {
  1736. try {
  1737. const res = await getDetail(targetTask.sessionId);
  1738. const messages = res?.messages || (Array.isArray(res) ? res : res?.data);
  1739. if (Array.isArray(messages)) {
  1740. targetTask.messages = transformHistoryToMessages(messages);
  1741. }
  1742. historyLoadedTasks.add(targetTask.id);
  1743. } catch (error) {
  1744. console.error('加载历史会话失败:', error);
  1745. }
  1746. }
  1747. if (targetTask.sessionId) {
  1748. fetchContext(targetTask.sessionId);
  1749. fetchSessionMode(targetTask.sessionId);
  1750. } else {
  1751. contextUsed.value = 0;
  1752. contextPercent.value = 0;
  1753. contextBreakdown.value = { messages: 0, mcp: 0, skills: 0, system_prompt: 0, other: 0 };
  1754. editMode.value = 'full';
  1755. }
  1756. messages.value = targetTask.messages && targetTask.messages.length > 0 ? [...targetTask.messages] : getDefaultMessages();
  1757. syncTodoBarFromMessages();
  1758. pendingFile.value = null;
  1759. showFileList.value = false;
  1760. inputMessage.value = '';
  1761. await nextTick(() => {
  1762. chatMessagesRef.value?.forceScrollToBottom();
  1763. });
  1764. }
  1765. }
  1766. );
  1767. // 拖拽相关(使用普通变量避免 mousemove 触发 Vue 响应式导致卡顿)
  1768. let isDragging = false;
  1769. let dragStartX = 0;
  1770. let dragStartY = 0;
  1771. let modalStartLeft = 0;
  1772. let modalStartTop = 0;
  1773. let draggedEl: HTMLElement | null = null;
  1774. const findModalWrap = (target: HTMLElement): HTMLElement | null =>
  1775. target.closest<HTMLElement>('.zxm-modal-wrap, .ant-modal-wrap, [class*="modal-wrap"]');
  1776. const queryModalWrap = (): HTMLElement | null => document.querySelector<HTMLElement>('.zxm-modal-wrap, .ant-modal-wrap, [class*="modal-wrap"]');
  1777. // 统一处理 modal-wrap 内联样式:全屏时置顶铺满,否则恢复默认
  1778. const applyWrapStyles = (fullscreen: boolean) => {
  1779. const wraps = document.querySelectorAll<HTMLElement>('.zxm-modal-wrap, .ant-modal-wrap, [class*="modal-wrap"]');
  1780. wraps.forEach((wrap) => {
  1781. wrap.style.position = '';
  1782. wrap.style.left = '';
  1783. wrap.style.top = fullscreen ? '0' : '';
  1784. wrap.style.right = '';
  1785. wrap.style.bottom = '';
  1786. wrap.style.width = '';
  1787. wrap.style.height = '';
  1788. wrap.style.margin = fullscreen ? '0' : '';
  1789. wrap.style.padding = fullscreen ? '0' : '';
  1790. wrap.style.transform = '';
  1791. });
  1792. };
  1793. const centerModal = () => {
  1794. nextTick(() => {
  1795. applyWrapStyles(isFullscreen.value);
  1796. draggedEl = null;
  1797. });
  1798. };
  1799. const onDragStart = (e: MouseEvent) => {
  1800. if (isFullscreen.value) return;
  1801. draggedEl = findModalWrap(e.target as HTMLElement) || queryModalWrap();
  1802. if (!draggedEl) return;
  1803. isDragging = true;
  1804. dragStartX = e.clientX;
  1805. dragStartY = e.clientY;
  1806. const rect = draggedEl.getBoundingClientRect();
  1807. modalStartLeft = rect.left;
  1808. modalStartTop = rect.top;
  1809. draggedEl.style.position = 'fixed';
  1810. draggedEl.style.left = `${rect.left}px`;
  1811. draggedEl.style.top = `${rect.top}px`;
  1812. draggedEl.style.margin = '0';
  1813. draggedEl.style.transform = 'none';
  1814. document.addEventListener('mousemove', onDragMove);
  1815. document.addEventListener('mouseup', onDragEnd);
  1816. };
  1817. const onDragMove = (e: MouseEvent) => {
  1818. if (!isDragging || !draggedEl) return;
  1819. draggedEl.style.left = `${modalStartLeft + (e.clientX - dragStartX)}px`;
  1820. draggedEl.style.top = `${modalStartTop + (e.clientY - dragStartY)}px`;
  1821. };
  1822. const onDragEnd = () => {
  1823. isDragging = false;
  1824. document.removeEventListener('mousemove', onDragMove);
  1825. document.removeEventListener('mouseup', onDragEnd);
  1826. };
  1827. watch(
  1828. () => props.visible,
  1829. (newVisible) => {
  1830. if (newVisible) {
  1831. centerModal();
  1832. }
  1833. }
  1834. );
  1835. onBeforeUnmount(() => {
  1836. document.removeEventListener('mousemove', onDragMove);
  1837. document.removeEventListener('mouseup', onDragEnd);
  1838. window.removeEventListener('resize', onResize);
  1839. // 组件卸载时主动断开所有任务的流式连接
  1840. taskAbortControllers.forEach((controller) => controller.abort());
  1841. // Abort in-flight FileReader if any
  1842. if (activeFileReader.value) {
  1843. activeFileReader.value.abort();
  1844. activeFileReader.value = null;
  1845. }
  1846. });
  1847. </script>
  1848. <style scoped lang="less">
  1849. .ai-container {
  1850. display: flex;
  1851. height: 700px;
  1852. gap: 10px;
  1853. overflow: hidden;
  1854. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  1855. }
  1856. .collapse-btn {
  1857. position: absolute;
  1858. top: 16px;
  1859. left: 24px;
  1860. z-index: 10;
  1861. width: 32px;
  1862. height: 32px;
  1863. background: #1a6696;
  1864. border-radius: 4px;
  1865. display: flex;
  1866. align-items: center;
  1867. justify-content: center;
  1868. cursor: pointer;
  1869. transition: background 0.3s;
  1870. &:hover {
  1871. background: #1f7ab8;
  1872. }
  1873. .collapse-icon {
  1874. width: 16px;
  1875. height: 16px;
  1876. background-image: var(--img-chat-collapse-icon);
  1877. background-repeat: no-repeat;
  1878. background-size: 100% 100%;
  1879. &.collapsed {
  1880. background-image: var(--img-chat-expand-icon);
  1881. }
  1882. }
  1883. }
  1884. .task-panel-wrapper {
  1885. width: 300px;
  1886. flex-shrink: 0;
  1887. overflow: hidden;
  1888. transition:
  1889. width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
  1890. margin 0.35s cubic-bezier(0.4, 0, 0.2, 1),
  1891. opacity 0.25s ease;
  1892. &.collapsed {
  1893. width: 0;
  1894. margin: 0;
  1895. opacity: 0;
  1896. }
  1897. }
  1898. .chat-panel {
  1899. flex: 1;
  1900. display: flex;
  1901. position: relative;
  1902. flex-direction: column;
  1903. background-image: var(--img-chat-panel-bg);
  1904. background-repeat: no-repeat;
  1905. background-size: 100% 100%;
  1906. border-radius: 4px;
  1907. overflow: hidden;
  1908. min-width: 0;
  1909. }
  1910. .right-panel {
  1911. width: calc(50% - 140px);
  1912. height: 100%;
  1913. display: flex;
  1914. flex-direction: column;
  1915. background-image: var(--img-chat-panel-bg);
  1916. background-repeat: no-repeat;
  1917. background-size: 100% 100%;
  1918. border-radius: 4px;
  1919. &.full {
  1920. flex: 1;
  1921. width: auto;
  1922. min-width: 0;
  1923. }
  1924. flex-shrink: 0;
  1925. }
  1926. /* 右侧面板滑入滑出过渡动画 */
  1927. :deep(.right-panel-slide-enter-active) {
  1928. transition:
  1929. opacity 0.3s ease,
  1930. transform 0.3s ease;
  1931. }
  1932. :deep(.right-panel-slide-leave-active) {
  1933. transition:
  1934. opacity 0.25s ease,
  1935. transform 0.25s ease;
  1936. }
  1937. :deep(.right-panel-slide-enter-from) {
  1938. opacity: 0;
  1939. transform: translateX(30px);
  1940. }
  1941. :deep(.right-panel-slide-leave-to) {
  1942. opacity: 0;
  1943. transform: translateX(30px);
  1944. }
  1945. .draggable-title {
  1946. cursor: grab;
  1947. user-select: none;
  1948. &:active {
  1949. cursor: grabbing;
  1950. }
  1951. &.no-drag {
  1952. cursor: default;
  1953. &:active {
  1954. cursor: default;
  1955. }
  1956. }
  1957. }
  1958. </style>
  1959. <style lang="less">
  1960. .ai-assistant-modal {
  1961. .zxm-modal-content {
  1962. background-image: var(--img-chat-modal-bg);
  1963. background-repeat: no-repeat;
  1964. background-size: 100% 100%;
  1965. background-color: unset !important;
  1966. box-shadow: none;
  1967. padding: 0;
  1968. border: none !important;
  1969. transition: width 0.3s ease;
  1970. }
  1971. /* 全屏切换缩放动画 */
  1972. @keyframes modal-zoom-in {
  1973. from {
  1974. transform: scale(0.85);
  1975. opacity: 0.6;
  1976. }
  1977. to {
  1978. transform: scale(1);
  1979. opacity: 1;
  1980. }
  1981. }
  1982. @keyframes modal-zoom-out {
  1983. from {
  1984. transform: scale(1.15);
  1985. opacity: 0.6;
  1986. }
  1987. to {
  1988. transform: scale(1);
  1989. opacity: 1;
  1990. }
  1991. }
  1992. .zxm-modal-content.modal-zoom-in-anim {
  1993. animation: modal-zoom-in 0.3s ease forwards;
  1994. }
  1995. .zxm-modal-content.modal-zoom-out-anim {
  1996. animation: modal-zoom-out 0.3s ease forwards;
  1997. }
  1998. .zxm-modal-close {
  1999. background-image: var(--img-chat-close-bg);
  2000. background-repeat: no-repeat;
  2001. background-size: 100% 100%;
  2002. top: 12px;
  2003. right: 20px;
  2004. width: 38px;
  2005. height: 38px;
  2006. .zxm-modal-close-x {
  2007. width: 38px;
  2008. height: 38px;
  2009. }
  2010. svg {
  2011. width: 26px;
  2012. height: 26px;
  2013. margin-bottom: 4px;
  2014. }
  2015. }
  2016. .maximize-btn {
  2017. position: absolute;
  2018. top: 12px;
  2019. right: 72px;
  2020. width: 38px;
  2021. height: 38px;
  2022. background-image: var(--img-chat-close-bg);
  2023. background-repeat: no-repeat;
  2024. background-size: 100% 100%;
  2025. display: flex;
  2026. align-items: center;
  2027. justify-content: center;
  2028. cursor: pointer;
  2029. z-index: 10;
  2030. .maximize-icon {
  2031. width: 22px;
  2032. height: 22px;
  2033. background-image: var(--img-chat-maximize-icon);
  2034. background-repeat: no-repeat;
  2035. background-size: 100% 100%;
  2036. &.minimized {
  2037. background-image: var(--img-chat-minimize-icon);
  2038. }
  2039. }
  2040. }
  2041. &.fullscreen {
  2042. top: 0 !important;
  2043. padding: 0 !important;
  2044. max-width: 100vw !important;
  2045. margin: 0 !important;
  2046. background-color: #09172c;
  2047. .zxm-modal-wrap,
  2048. .ant-modal-wrap {
  2049. padding: 0 !important;
  2050. margin: 0 !important;
  2051. top: 0 !important;
  2052. }
  2053. .zxm-modal-content {
  2054. width: 100vw !important;
  2055. height: 100vh !important;
  2056. max-width: 100vw !important;
  2057. margin: 0;
  2058. border-radius: 0;
  2059. overflow: hidden;
  2060. background-image: var(--img-chat-fs-modal-bg);
  2061. }
  2062. .zxm-modal-header {
  2063. height: 90px;
  2064. background-image: var(--img-chat-fs-header-bg) !important;
  2065. background-repeat: no-repeat;
  2066. background-size: 100% 100%;
  2067. margin-bottom: 16px;
  2068. }
  2069. .no-drag {
  2070. cursor: default;
  2071. font-size: 32px !important;
  2072. }
  2073. .zxm-modal-title {
  2074. height: 90px;
  2075. }
  2076. .zxm-modal-body {
  2077. height: calc(100vh - 120px);
  2078. overflow: hidden;
  2079. padding: 0 24px 12px;
  2080. }
  2081. .ai-container {
  2082. height: 100%;
  2083. overflow: hidden;
  2084. }
  2085. .chat-panel {
  2086. background-image: var(--img-chat-fs-panel-bg) !important;
  2087. }
  2088. .chat-header {
  2089. padding: 0 12px;
  2090. height: 50px;
  2091. }
  2092. .collapse-btn {
  2093. top: 60px;
  2094. background-image: var(--img-chat-fs-collapse-btn-bg) !important;
  2095. background-repeat: no-repeat;
  2096. background-size: 100% 100%;
  2097. }
  2098. .task-list-panel {
  2099. padding: 20px;
  2100. background-image: var(--img-chat-fs-task-panel-bg) !important;
  2101. background-repeat: no-repeat !important;
  2102. background-size: 100% 100% !important;
  2103. }
  2104. .options-area {
  2105. gap: 12px;
  2106. }
  2107. .options-area-item {
  2108. background-image: var(--img-chat-fs-options-item-bg) !important;
  2109. background-repeat: no-repeat !important;
  2110. background-size: 100% 100% !important;
  2111. &.active,
  2112. &:active {
  2113. background-image: var(--img-chat-fs-options-item-active-bg) !important;
  2114. }
  2115. .options-img {
  2116. background-image: none !important;
  2117. }
  2118. }
  2119. .chat-header-title {
  2120. height: 40px;
  2121. line-height: 40px;
  2122. position: relative;
  2123. background-image: var(--img-chat-fs-header-title-bg) !important;
  2124. background-repeat: no-repeat !important;
  2125. background-size: auto 100% !important;
  2126. padding: 0 28px;
  2127. &::before {
  2128. content: '';
  2129. position: absolute;
  2130. left: 0;
  2131. top: 50%;
  2132. transform: translateY(-50%);
  2133. width: 40px;
  2134. height: 40px;
  2135. background-image: var(--img-chat-fs-header-title-icon);
  2136. background-repeat: no-repeat;
  2137. background-size: 100% 100%;
  2138. }
  2139. }
  2140. .chat-header-title-wrapper {
  2141. .title-edit-input {
  2142. height: 36px;
  2143. font-size: 16px;
  2144. background: rgba(10, 132, 255, 0.15);
  2145. border-color: rgba(10, 132, 255, 0.6);
  2146. }
  2147. .title-edit-btn {
  2148. width: 24px;
  2149. height: 24px;
  2150. background-size: 16px 16px;
  2151. }
  2152. }
  2153. .chat-input-area {
  2154. margin: 24px;
  2155. }
  2156. .right-panel {
  2157. background-image: var(--img-chat-fs-panel-bg) !important;
  2158. }
  2159. :deep(.panel-tab-bar) {
  2160. padding: 14px 16px 0;
  2161. }
  2162. .schedule-panel,
  2163. .skill-panel,
  2164. .sub-agent-panel {
  2165. background-image: var(--img-chat-fs-panel-bg) !important;
  2166. }
  2167. }
  2168. .zxm-modal-header {
  2169. background-color: unset !important;
  2170. background: unset;
  2171. border: none !important;
  2172. padding: 8px;
  2173. backdrop-filter: unset;
  2174. display: flex;
  2175. justify-content: center;
  2176. }
  2177. .zxm-modal-title {
  2178. width: 100%;
  2179. height: 60px;
  2180. display: flex;
  2181. align-items: center;
  2182. justify-content: center;
  2183. .draggable-title {
  2184. color: #fff;
  2185. font-family: var(--vet-font-family);
  2186. letter-spacing: 3px;
  2187. font-size: 24px;
  2188. font-weight: 100;
  2189. line-height: 1.4;
  2190. }
  2191. }
  2192. .zxm-modal-body {
  2193. padding: 12px 24px !important;
  2194. }
  2195. }
  2196. .delete-task-confirm-modal {
  2197. .zxm-modal-confirm-title,
  2198. .zxm-modal-confirm-content {
  2199. color: #fff;
  2200. }
  2201. }
  2202. </style>