From f55d84f8479f35f780c535d2d4f4836727363255 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期五, 09 十月 2026 09:38:10 +0800
Subject: [PATCH] fix: 首次提交
---
src/api/authApi.js | 21
src/stores/authStore.js | 127 +
src/utils/markdown.js | 209 +
src/components/MessageItem.vue | 716 ++++++
src/api/chatApi.js | 50
src/styles/global.css | 220 +
src/components/FileUpload.vue | 289 ++
index.html | 12
src/stores/chatStore.js | 604 +++++
src/api/fileApi.js | 162 +
src/components/Sidebar.vue | 498 ++++
src/utils/treeBuild.js | 174 +
src/views/AdminKnowledge.vue | 583 ++++
src/views/Chat.vue | 101
src/api/categoryApi.js | 62
src/components/ChatView.vue | 1428 ++++++++++++
src/views/Files.vue | 696 +++++
src/router/index.js | 71
src/views/Login.vue | 227 +
src/utils/sse.js | 269 ++
src/components/AuthenticatedImage.vue | 203 +
src/main.js | 19
src/api/axios.js | 94
src/App.vue | 41
src/components/CategoryPicker.vue | 175 +
25 files changed, 7,051 insertions(+), 0 deletions(-)
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..dedd6c1
--- /dev/null
+++ b/index.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Custom-WebUI</title>
+ </head>
+ <body>
+ <div id="app"></div>
+ <script type="module" src="/src/main.js"></script>
+ </body>
+</html>
diff --git a/src/App.vue b/src/App.vue
new file mode 100644
index 0000000..575b674
--- /dev/null
+++ b/src/App.vue
@@ -0,0 +1,41 @@
+<template>
+ <n-config-provider :theme-overrides="themeOverrides">
+ <n-message-provider>
+ <n-dialog-provider>
+ <router-view />
+ </n-dialog-provider>
+ </n-message-provider>
+ </n-config-provider>
+</template>
+
+<script setup>
+import { NConfigProvider, NMessageProvider, NDialogProvider } from 'naive-ui'
+
+/**
+ * 涓婚寰皟锛屽悜 Open-WebUI 鐨勫厠鍒堕鏍奸潬鎷細
+ * 涓昏壊鐢ㄤ腑鎬х伆钃濊�岄潪 NaiveUI 榛樿鐨勪寒缁匡紝鍦嗚鏀舵暃鍒� 8px銆�
+ */
+const themeOverrides = {
+ common: {
+ primaryColor: '#4b5563',
+ primaryColorHover: '#374151',
+ primaryColorPressed: '#1f2937',
+ primaryColorSuppl: '#4b5563',
+ borderRadius: '8px',
+ fontSize: '14px'
+ },
+ Button: {
+ borderRadiusMedium: '8px'
+ },
+ Card: {
+ borderRadius: '10px'
+ }
+}
+</script>
+
+<style>
+#app {
+ height: 100vh;
+ overflow: hidden;
+}
+</style>
diff --git a/src/api/authApi.js b/src/api/authApi.js
new file mode 100644
index 0000000..1c4a38b
--- /dev/null
+++ b/src/api/authApi.js
@@ -0,0 +1,21 @@
+import http from './axios'
+
+/** 鐧诲綍锛岃繑鍥� { token, expiresAt, user } */
+export function login(payload) {
+ return http.post('/auth/login', payload)
+}
+
+/** 娉ㄥ唽 */
+export function register(payload) {
+ return http.post('/auth/register', payload)
+}
+
+/** 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛锛岀敤浜庡埛鏂伴〉闈㈠悗鏍¢獙 token 鏄惁浠嶇劧鏈夋晥 */
+export function fetchCurrentUser() {
+ return http.get('/auth/me')
+}
+
+/** 淇敼瀵嗙爜 */
+export function changePassword(payload) {
+ return http.put('/auth/password', payload)
+}
diff --git a/src/api/axios.js b/src/api/axios.js
new file mode 100644
index 0000000..894d8de
--- /dev/null
+++ b/src/api/axios.js
@@ -0,0 +1,94 @@
+import axios from 'axios'
+
+/**
+ * axios 瀹炰緥灏佽銆�
+ *
+ * 涓や釜鏍稿績鑱岃矗锛�
+ * 1. 鑷姩鎼哄甫 JWT锛堣姹傛嫤鎴櫒锛�
+ * 2. 缁熶竴瑙e寘 {code,msg,data} 骞舵妸涓氬姟閿欒杞垚寮傚父锛堝搷搴旀嫤鎴櫒锛�
+ *
+ * 瑙e寘鍚庝笟鍔′唬鐮佺洿鎺ユ嬁鍒� data锛屼笉鐢ㄦ瘡娆″啓 res.data.data銆�
+ */
+const http = axios.create({
+ baseURL: '/api',
+ timeout: 120000
+})
+
+/** 鏈巿鏉冩椂鐨勫洖璋冿紝鐢� authStore 娉ㄥ唽锛岄伩鍏嶆澶勭洿鎺� import store 閫犳垚寰幆渚濊禆 */
+let onUnauthorized = null
+
+export function setUnauthorizedHandler(handler) {
+ onUnauthorized = handler
+}
+
+// ---------------- 璇锋眰鎷︽埅锛氭敞鍏� token ----------------
+http.interceptors.request.use(
+ (config) => {
+ // 浠� localStorage 鐩存帴璇伙紝鑰屼笉鏄� import store锛�
+ // 閬垮厤 store 鍒濆鍖栭『搴忛棶棰樺鑷寸殑銆宼oken 杩樻病鎭㈠灏卞彂璇锋眰銆�
+ const token = localStorage.getItem('webui_token')
+ if (token) {
+ config.headers.Authorization = `Bearer ${token}`
+ }
+ return config
+ },
+ (error) => Promise.reject(error)
+)
+
+// ---------------- 鍝嶅簲鎷︽埅锛氳В鍖呬笌閿欒褰掍竴鍖� ----------------
+http.interceptors.response.use(
+ (response) => {
+ const body = response.data
+
+ // 浜岃繘鍒跺搷搴旓紙鍥剧墖銆佹枃浠朵笅杞斤級鐩存帴杩斿洖 Blob/ArrayBuffer銆�
+ // 涓嶈兘璧颁笅闈㈢殑 Result 瑙e寘锛氬畠涓嶆槸 {code,msg,data} 缁撴瀯锛�
+ // 涓旇В鍖呴�昏緫浼氭妸瀹冨綋鎴愭櫘閫氬璞″鐞嗐��
+ if (body instanceof Blob || body instanceof ArrayBuffer) {
+ return body
+ }
+
+ // SSE 鎴栨枃浠朵笅杞界瓑闈� JSON 鍝嶅簲鐩存帴閫忎紶
+ if (body === null || typeof body !== 'object' || !('code' in body)) {
+ return body
+ }
+
+ if (body.code === 200) {
+ return body.data
+ }
+
+ // 涓氬姟灞傞敊璇細缁熶竴鎶涘嚭锛屼究浜庤皟鐢ㄦ柟 try/catch
+ const error = new Error(body.msg || '璇锋眰澶辫触')
+ error.code = body.code
+ return Promise.reject(error)
+ },
+ (error) => {
+ const status = error.response?.status
+ const body = error.response?.data
+
+ if (status === 401) {
+ // token 澶辨晥锛氭竻鐞嗘湰鍦扮姸鎬佸苟璺崇櫥褰曢〉銆�
+ // 閫氳繃鍥炶皟鑰屼笉鏄洿鎺ユ搷浣� router锛岄槻姝� store 涓� router 寰幆渚濊禆銆�
+ if (onUnauthorized) {
+ onUnauthorized()
+ }
+ return Promise.reject(new Error(body?.msg || '鐧诲綍宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�'))
+ }
+
+ // 鎶婂悗绔殑 Result.msg 鎻愬彇鍑烘潵锛岃 UI 鑳芥樉绀烘湁鎰忎箟鐨勬彁绀�
+ let message = body?.msg
+ if (!message) {
+ if (status === 403) message = '娌℃湁鏉冮檺鎵ц璇ユ搷浣�'
+ else if (status === 404) message = '璇锋眰鐨勮祫婧愪笉瀛樺湪'
+ else if (status >= 500) message = '鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇锋煡鐪嬪悗绔棩蹇�'
+ else if (error.code === 'ECONNABORTED') message = '璇锋眰瓒呮椂'
+ else if (!error.response) message = '鏃犳硶杩炴帴鏈嶅姟鍣紝璇风‘璁ゅ悗绔凡鍚姩'
+ else message = error.message
+ }
+
+ const wrapped = new Error(message)
+ wrapped.code = status
+ return Promise.reject(wrapped)
+ }
+)
+
+export default http
diff --git a/src/api/categoryApi.js b/src/api/categoryApi.js
new file mode 100644
index 0000000..3d40c13
--- /dev/null
+++ b/src/api/categoryApi.js
@@ -0,0 +1,62 @@
+import http from './axios'
+
+/**
+ * 鑾峰彇鍙鐨勭煡璇嗗簱鍒嗙被銆�
+ *
+ * 杩斿洖鐨勬瘡涓垎绫诲甫锛�
+ * - fileCount / ingestedCount锛氭枃妗f�绘暟 / 宸插叆搴撴暟
+ * - collectionNames锛氬凡鍏ュ簱鏂囨。瀵瑰簲鐨勯泦鍚堝悕锛堟暣绫荤粦瀹氱敤锛�
+ * - canManage锛氬綋鍓嶇敤鎴锋槸鍚︽湁鏉冩敼鍚嶃�佸垹闄ゃ�佸線閲屾斁鏂囨。
+ *
+ * @param {number|null} chatId 浼犲叆鏃朵細鏍囪鍚勫垎绫绘槸鍚﹀凡缁戝畾鍒拌浼氳瘽
+ */
+export function listCategories(chatId = null) {
+ return http.get('/categories', { params: chatId != null ? { chatId } : {} })
+}
+
+/** 鍒涘缓鍒嗙被锛涚鐞嗗憳鍙紶 global=true 鍒涘缓鍏ㄥ憳鍙鐨勫垎绫� */
+export function createCategory(name, description = null, global = false) {
+ return http.post('/categories', { name, description, global })
+}
+
+/** 閲嶅懡鍚� / 淇敼璇存槑 */
+export function updateCategory(categoryId, name, description = null) {
+ return http.put(`/categories/${categoryId}`, { name, description })
+}
+
+/**
+ * 鍒犻櫎鍒嗙被銆�
+ *
+ * 鍒嗙被鍐呯殑**鏂囨。涓嶄細琚垹闄�**锛屽彧浼氬彉鎴愩�屾湭鍒嗙被銆嶃��
+ */
+export function deleteCategory(categoryId) {
+ return http.delete(`/categories/${categoryId}`)
+}
+
+/**
+ * 鎶婃枃妗e綊鍏ュ垎绫伙紱assign=false 琛ㄧず绉诲嚭鍒嗙被銆�
+ */
+export function assignFileToCategory(categoryId, fileId, assign = true) {
+ return http.post(`/categories/${categoryId}/files/${fileId}`, null, { params: { assign } })
+}
+
+// ============================================================
+// 鏁寸被缁戝畾
+// ============================================================
+
+/**
+ * 鏁寸被缁戝畾 / 瑙g粦銆�
+ *
+ * 鍚庣瀛樼殑鏄�**鍒嗙被 id**锛屾绱㈡椂鎵嶅睍寮�鎴愰泦鍚� 鈥斺��
+ * 鍥犳涔嬪悗寰�鍒嗙被閲屾柊澧炵殑鏂囨。锛屽凡鏈変細璇濅細鑷姩妫�绱㈠埌銆�
+ *
+ * @returns 璇ヤ細璇濆綋鍓嶇粦瀹氱殑鍒嗙被 id 鍒楄〃
+ */
+export function bindCategory(chatId, categoryId, bind = true) {
+ return http.post('/rag/bind-category', { chatId, categoryId, bind })
+}
+
+/** 鏌ヨ浼氳瘽宸茬粦瀹氱殑鍒嗙被 id 鍒楄〃 */
+export function listCategoryBindings(chatId) {
+ return http.get(`/rag/bind-category/${chatId}`)
+}
diff --git a/src/api/chatApi.js b/src/api/chatApi.js
new file mode 100644
index 0000000..a970691
--- /dev/null
+++ b/src/api/chatApi.js
@@ -0,0 +1,50 @@
+import http from './axios'
+
+/** 浼氳瘽鍒楄〃 */
+export function listChats() {
+ return http.get('/chats')
+}
+
+/**
+ * 鎼滅储鍘嗗彶瀵硅瘽銆�
+ *
+ * 鍚庣鍚屾椂鍖归厤鏍囬涓庢秷鎭唴瀹癸紝杩斿洖鐨勬瘡涓�椤瑰甫锛�
+ * - matchSnippet锛氬懡涓鐨勪笂涓嬫枃鐗囨
+ * - matchType锛歵itle / message / both
+ */
+export function searchChats(keyword, limit = 30) {
+ return http.get('/chats/search', { params: { q: keyword, limit } })
+}
+
+/** 鏂板缓浼氳瘽 */
+export function createChat(payload = {}) {
+ return http.post('/chats', payload)
+}
+
+/**
+ * 淇敼浼氳瘽鏍囬鎴栨ā鍨嬪弬鏁般��
+ * meta 鏄暣浣撹鐩栬涔夛紝璇锋彁浜ゅ畬鏁寸殑鍙傛暟瀵硅薄銆�
+ */
+export function updateChat(chatId, payload) {
+ return http.put(`/chats/${chatId}`, payload)
+}
+
+/** 鍒犻櫎浼氳瘽锛堢骇鑱斿垹闄ゆ秷鎭級 */
+export function deleteChat(chatId) {
+ return http.delete(`/chats/${chatId}`)
+}
+
+/** 鑾峰彇浼氳瘽鐨勬秷鎭爲锛堟牴鑺傜偣鏁扮粍锛岃妭鐐瑰唴宓� children锛� */
+export function listMessages(chatId) {
+ return http.get(`/chats/${chatId}/messages`)
+}
+
+/** 缂栬緫娑堟伅鍐呭 */
+export function updateMessage(chatId, messageId, payload) {
+ return http.put(`/chats/${chatId}/messages/${messageId}`, payload)
+}
+
+/** 鍒犻櫎娑堟伅鍙婂叾鍏ㄩ儴瀛愬瓩 */
+export function deleteMessage(chatId, messageId) {
+ return http.delete(`/chats/${chatId}/messages/${messageId}`)
+}
diff --git a/src/api/fileApi.js b/src/api/fileApi.js
new file mode 100644
index 0000000..6a2cd07
--- /dev/null
+++ b/src/api/fileApi.js
@@ -0,0 +1,162 @@
+import http from './axios'
+
+/**
+ * 涓婁紶鏂囦欢锛宑hatId 涓虹┖琛ㄧず鍏叡鐭ヨ瘑搴撴枃浠躲��
+ *
+ * @param {File} file
+ * @param {number} chatId 缁戝畾鐨勪細璇濓紝null 琛ㄧず涓嶇粦瀹�
+ * @param {Function} onProgress 涓婁紶杩涘害鍥炶皟锛�0-100锛�
+ * @param {boolean} autoIngest 涓婁紶鍚庢槸鍚︾珛鍗冲悜閲忓寲锛岄粯璁� true
+ *
+ * 瓒呮椂缁欏埌 10 鍒嗛挓锛歛utoIngest 涓� true 鏃讹紝杩欎釜璇锋眰瑕佺瓑瑙f瀽 + embedding +
+ * 鍐欏悜閲忓簱鍏ㄩ儴瀹屾垚鎵嶈繑鍥烇紝澶ф枃妗e嚑鍒嗛挓寰堟甯搞��
+ */
+export function uploadFile(file, chatId = null, onProgress = null, autoIngest = true, categoryId = null) {
+ const form = new FormData()
+ form.append('file', file)
+ if (chatId != null) {
+ form.append('chatId', chatId)
+ }
+ return http.post('/files/upload', form, {
+ params: { autoIngest, categoryId },
+ headers: { 'Content-Type': 'multipart/form-data' },
+ timeout: 600000,
+ onUploadProgress: (event) => {
+ if (onProgress && event.total) {
+ onProgress(Math.round((event.loaded / event.total) * 100))
+ }
+ }
+ })
+}
+
+/** 鏂囦欢鍒楄〃 */
+export function listFiles(chatId = null) {
+ return http.get('/files', { params: chatId != null ? { chatId } : {} })
+}
+
+/** 鍒犻櫎鏂囦欢锛堝悓鏃舵竻鐞嗙鐩樻枃浠朵笌鍚戦噺闆嗗悎锛� */
+export function deleteFile(fileId) {
+ return http.delete(`/files/${fileId}`)
+}
+
+/**
+ * 瑙﹀彂鍚戦噺鍖栧叆搴撱��
+ * 杩欐槸鑰楁椂鎺ュ彛锛堣В鏋� + embedding锛夛紝澶ф枃妗e彲鑳芥暟鍒嗛挓锛岄渶缁欒冻瓒呮椂銆�
+ */
+export function ingestFile(fileId) {
+ return http.post(`/files/${fileId}/ingest`, null, { timeout: 900000 })
+}
+
+/** RAG 鏈嶅姟鍋ュ悍鐘舵�佷笌宸叉嫢鏈夌殑鐭ヨ瘑搴撻泦鍚� */
+export function ragHealth() {
+ return http.get('/rag/health')
+}
+
+/**
+ * 鎶婄煡璇嗗簱闆嗗悎缁戝畾鍒颁細璇濓紙鍏ㄩ噺瑕嗙洊璇箟锛夈��
+ *
+ * 杩斿洖鍊兼槸**鍚庣瀹為檯缁戝畾鎴愬姛**鐨勯泦鍚堝垪琛紝鍙兘涓庝紶鍏ョ殑涓嶄竴鑷� 鈥斺��
+ * 宸插け鏁堢殑闆嗗悎锛堟枃妗h鍒犮�佽鍙栨秷鍏ㄥ眬鏍囪锛変細琚悗绔拷鐣ャ��
+ * 璋冪敤鏂瑰簲涓庝紶鍏ュ垪琛ㄦ瘮瀵癸紝鎶婅鍓旈櫎鐨勯」浠庢湰鍦扮姸鎬侀噷鍚屾鎺夈��
+ */
+export function bindCollections(chatId, collectionNames) {
+ return http.post('/rag/bind', { chatId, collectionNames })
+}
+
+/** 鏌ヨ浼氳瘽宸茬粦瀹氱殑闆嗗悎 */
+export function listBindings(chatId) {
+ return http.get(`/rag/bind/${chatId}`)
+}
+
+/** 瑙g粦浼氳瘽鐨勫叏閮ㄧ煡璇嗗簱 */
+export function unbindCollections(chatId) {
+ return http.delete(`/rag/bind/${chatId}`)
+}
+
+/** 鐩存帴璋冪敤鍚庣浠g悊鐨勫悜閲忔绱紙璋冭瘯鐢級 */
+export function searchRag(payload) {
+ return http.post('/rag/search', payload)
+}
+
+// ============================================================
+// 鍏ㄥ眬鐭ヨ瘑搴擄紙绠$悊鍛樼淮鎶わ紝鍏ㄥ憳鍙粦瀹氾級
+// ============================================================
+
+/**
+ * 绠$悊鍛樹笂浼犲叏灞�鐭ヨ瘑搴撴枃浠躲��
+ *
+ * @param {boolean} autoIngest 涓婁紶鍚庢槸鍚︾珛鍗冲悜閲忓寲锛岄粯璁� true 鈥斺��
+ * 鍏ㄥ眬鐭ヨ瘑搴撹嫢涓嶅叆搴擄紝鎵�鏈夌敤鎴烽兘妫�绱笉鍒帮紝鐣欑潃鏈叆搴撶姸鎬佹病鏈夋剰涔夈��
+ */
+export function uploadGlobalFile(file, onProgress = null, autoIngest = true, categoryId = null) {
+ const form = new FormData()
+ form.append('file', file)
+ return http.post('/files/global/upload', form, {
+ params: { autoIngest, categoryId },
+ headers: { 'Content-Type': 'multipart/form-data' },
+ timeout: 600000,
+ onUploadProgress: (event) => {
+ if (onProgress && event.total) {
+ onProgress(Math.round((event.loaded / event.total) * 100))
+ }
+ }
+ })
+}
+
+/** 鍒楀嚭鍏ㄩ儴鍏ㄥ眬鐭ヨ瘑搴撴枃浠讹紙浠讳綍鐧诲綍鐢ㄦ埛閮藉彲璋冪敤锛岀敤浜庡彂鐜板彲缁戝畾鐨勫叕鍏辩煡璇嗗簱锛� */
+export function listGlobalFiles() {
+ return http.get('/files/global')
+}
+
+/** 璁句负 / 鍙栨秷鍏ㄥ眬鐭ヨ瘑搴擄紙浠呯鐞嗗憳锛� */
+export function setFileGlobal(fileId, isGlobal) {
+ return http.post(`/files/${fileId}/global`, null, { params: { isGlobal } })
+}
+
+// ============================================================
+// 鍥剧墖 OCR
+// ============================================================
+
+/** 瀵硅瘽涓笂浼犲浘鐗囨椂鍏佽鐨勭被鍨嬶紙涓庡悗绔櫧鍚嶅崟淇濇寔涓�鑷达級 */
+export const IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'webp', 'bmp', 'gif', 'tif', 'tiff']
+
+/**
+ * 涓婁紶鍥剧墖骞惰瘑鍒叾涓殑鏂囧瓧銆�
+ *
+ * 杩斿洖浣撳惈锛�
+ * - text锛氳瘑鍒嚭鐨勫畬鏁存枃鏈紝闅忔秷鎭彂缁欏ぇ妯″瀷浣滀负涓婁笅鏂�
+ * - fileId锛氬浘鐗囧湪鏈嶅姟绔殑 id锛岀敤浜庡湪娑堟伅閲屽睍绀哄師鍥�
+ * - imageUrl锛氬浘鐗囪闂湴鍧�
+ * - blocks锛氬悇鏂囨湰鍧楀強鍖呭洿鐩掞紝鍙敤浜庡湪鍥句笂鏍囨敞
+ *
+ * @param {File} file
+ * @param {number} chatId 缁戝畾鐨勪細璇濓紝鍙负绌�
+ * @param {Function} onProgress 涓婁紶杩涘害鍥炶皟
+ */
+export function recognizeImage(file, chatId = null, onProgress = null) {
+ const form = new FormData()
+ form.append('file', file)
+ // OCR 棣栨鍙兘鍔犺浇妯″瀷锛岃秴鏃剁粰瓒�
+ return http.post('/files/ocr', form, {
+ params: chatId != null ? { chatId } : {},
+ headers: { 'Content-Type': 'multipart/form-data' },
+ timeout: 300000,
+ onUploadProgress: (event) => {
+ if (onProgress && event.total) {
+ onProgress(Math.round((event.loaded / event.total) * 100))
+ }
+ }
+ })
+}
+
+/**
+ * 鏆傚瓨涓�娈甸檮浠舵枃鏈紝杩斿洖鐭� id銆�
+ *
+ * 鍥剧墖 OCR 鏂囧瓧鍙兘鍑犲崈瀛楋紝鐩存帴鏀捐繘 SSE 鐨� query string 浼氳秴鍑�
+ * Tomcat 鐨勮姹傝涓婇檺锛堜腑鏂� URL 缂栫爜绾� 9 瀛楄妭/瀛楋級锛�
+ * 寰楀埌 "Request header is too large" 杩欑闅句互鐞嗚В鐨� 400銆�
+ * 鍥犳鍏� POST 瀛樹笅鏉ワ紝鍙戦�佹秷鎭椂鍙甫杩斿洖鐨� id銆�
+ */
+export function storeAttachmentText(text) {
+ return http.post('/attachments/text', { text })
+}
diff --git a/src/components/AuthenticatedImage.vue b/src/components/AuthenticatedImage.vue
new file mode 100644
index 0000000..e120471
--- /dev/null
+++ b/src/components/AuthenticatedImage.vue
@@ -0,0 +1,203 @@
+<template>
+ <div class="authenticated-image">
+ <n-spin v-if="loading" size="small" class="img-loading" />
+ <div v-else-if="error" class="img-error" :title="error">
+ <span class="img-error-icon">鈿�</span>
+ <span class="img-error-text">鍥剧墖鍔犺浇澶辫触</span>
+ </div>
+ <img
+ v-else-if="objectUrl"
+ :src="objectUrl"
+ class="message-image-thumb"
+ :alt="alt"
+ :title="title"
+ />
+ </div>
+</template>
+
+<script setup>
+import { onBeforeUnmount, ref, watch } from 'vue'
+import { NSpin } from 'naive-ui'
+
+/**
+ * 闇�瑕侀壌鏉冪殑鍥剧墖銆�
+ *
+ * ## 涓轰粈涔堜笉鑳界洿鎺ュ啓 `<img src="/api/files/1/content">`
+ *
+ * 鍚庣鐨勬枃浠跺唴瀹规帴鍙i渶瑕� `Authorization: Bearer <jwt>`锛堝惁鍒欎汉浜虹煡閬� id
+ * 灏辫兘涓嬭浇鍒汉鐨勬枃浠讹紝鏄吀鍨嬬殑 IDOR 婕忔礊锛夈�備絾 `<img>` 鏍囩鍙戝嚭鐨勮姹�
+ * **涓嶄細鎼哄甫鑷畾涔夎姹傚ご** 鈥斺�� 娴忚鍣ㄥ彧鎸夊悓婧愯鍒欏甫涓� Cookie銆�
+ * 缁撴灉鏄悗绔繑鍥� 401锛屾祻瑙堝櫒鏄剧ず涓�涓�屽浘鐗囨崯鍧忋�嶇殑鐮村浘鏍囷紝
+ * 鑰� DOM 閲� `<img>` 鍏冪礌纭疄瀛樺湪锛岀敤銆屽厓绱犳暟閲忋�嶅仛鏂█鏍规湰鍙戠幇涓嶄簡銆�
+ *
+ * 姝g‘鍋氭硶锛氱敤 axios 甯� token 鍙栧洖浜岃繘鍒讹紙responseType: 'blob'锛夛紝
+ * 鍐� `URL.createObjectURL` 杞垚鏈湴鍙闂殑鍦板潃浜ょ粰 `<img>`銆�
+ *
+ * ## 缂撳瓨
+ *
+ * 妯″潡绾х紦瀛樻寜 fileId 澶嶇敤 objectURL锛�
+ * - 鍚屼竴鏉℃秷鎭殑缂╃暐鍥句笌鏀惧ぇ棰勮鍏辩敤涓�浠斤紝涓嶉噸澶嶈姹�
+ * - 浼氳瘽鍐呮粴鍔ㄣ�佸垏鍒嗘敮閲嶆覆鏌撲笉浼氬弽澶嶆媺鍙�
+ * objectURL 浼氭寔鏈夊唴瀛橈紝鍥犳杩欓噷**涓嶅湪鍗歌浇鏃� revoke**锛堝惁鍒欎細鎵撴柇
+ * 鍏朵粬鍦版柟瀵瑰悓涓�寮犲浘鐨勬樉绀猴級锛岃�屾槸鍦ㄩ〉闈㈡暣浣撳嵏杞芥椂缁熶竴閲婃斁銆�
+ */
+const props = defineProps({
+ /** 鍥剧墖鍦� upload_file 涓殑 id */
+ fileId: { type: [Number, String], required: true },
+ alt: { type: String, default: '鍥剧墖' },
+ title: { type: String, default: '' }
+})
+
+const emit = defineEmits(['loaded'])
+
+const objectUrl = ref('')
+const loading = ref(true)
+const error = ref('')
+
+/**
+ * fileId -> objectURL 缂撳瓨銆�
+ * value 涓� 'pending' 琛ㄧず璇锋眰杩涜涓紝閬垮厤鍚屼竴寮犲浘骞跺彂鎷夊娆°��
+ */
+const urlCache = new Map()
+const pendingResolvers = new Map()
+
+async function load() {
+ const key = String(props.fileId)
+ if (!key) return
+
+ // 鍛戒腑缂撳瓨
+ const cached = urlCache.get(key)
+ if (cached && cached !== 'pending') {
+ objectUrl.value = cached
+ loading.value = false
+ emit('loaded', cached)
+ return
+ }
+
+ // 宸叉湁鍚� id 鐨勮姹傚湪椋烇細绛夊畠鐨勭粨鏋滐紝閬垮厤閲嶅涓嬭浇
+ if (cached === 'pending') {
+ const url = await new Promise((resolve) => {
+ const list = pendingResolvers.get(key) || []
+ list.push(resolve)
+ pendingResolvers.set(key, list)
+ })
+ if (url) {
+ objectUrl.value = url
+ loading.value = false
+ emit('loaded', url)
+ }
+ return
+ }
+
+ urlCache.set(key, 'pending')
+ loading.value = true
+ error.value = ''
+
+ try {
+ // 鍔ㄦ�� import 閬垮厤涓� axios 灏佽浜х敓寰幆渚濊禆
+ const { default: http } = await import('@/api/axios')
+ const blob = await http.get(`/files/${key}/content`, { responseType: 'blob' })
+
+ // axios 鍦� responseType: 'blob' 鏃朵笉浼氳蛋鎴戜滑灏佽鐨� Result 瑙e寘
+ // 锛堝搷搴斾笉鏄� {code,msg,data} 缁撴瀯锛夛紝杩欓噷鎷垮埌鐨勬槸鍘熷 Blob
+ if (!(blob instanceof Blob)) {
+ throw new Error('鍝嶅簲涓嶆槸浜岃繘鍒舵暟鎹�')
+ }
+
+ const url = URL.createObjectURL(blob)
+ urlCache.set(key, url)
+ objectUrl.value = url
+ emit('loaded', url)
+ } catch (e) {
+ urlCache.delete(key)
+ error.value = e.message || '鍔犺浇澶辫触'
+ } finally {
+ loading.value = false
+ // 鍞ら啋绛夊緟涓殑缁勪欢
+ const list = pendingResolvers.get(key) || []
+ pendingResolvers.delete(key)
+ list.forEach((resolve) => resolve(urlCache.get(key) || ''))
+ }
+}
+
+watch(() => props.fileId, load, { immediate: true })
+
+/**
+ * 椤甸潰鏁翠綋鍗歌浇鏃剁粺涓�閲婃斁鎵�鏈� objectURL銆�
+ *
+ * 鍙竻涓�娆″嵆鍙細鏈粍浠惰鍗歌浇鏃讹紙渚嬪鍒囨崲浼氳瘽锛変笉閲婃斁锛�
+ * 鍥犱负缂撳瓨鏄法缁勪欢鍏变韩鐨勶紱鐪熸闇�瑕佸洖鏀跺唴瀛樼殑鏃舵満鏄寮�椤甸潰銆�
+ */
+function releaseAll() {
+ for (const [key, url] of urlCache) {
+ if (url && url !== 'pending') {
+ URL.revokeObjectURL(url)
+ }
+ }
+ urlCache.clear()
+}
+
+// 鐢� pagehide 鑰屼笉鏄� beforeunload锛氬墠鑰呭湪绉诲姩绔笌 bfcache 鍦烘櫙涓嬫洿鍙潬
+if (typeof window !== 'undefined') {
+ window.addEventListener('pagehide', releaseAll)
+}
+
+onBeforeUnmount(() => {
+ // 缁勪欢鍗歌浇鏃跺彧瑙g粦锛屼笉閲婃斁缂撳瓨锛堝叾浠栨秷鎭彲鑳借繕鍦ㄧ敤鍚屼竴寮犲浘锛�
+})
+</script>
+
+<style scoped>
+.authenticated-image {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ /*
+ * 灏哄瑙勫垯蹇呴』鏀惧湪**鏈粍浠剁殑 scoped 鏍峰紡**閲屻��
+ *
+ * 鏃╁墠鎶� .message-image-thumb 鐨� max-width 鍐欏湪 MessageItem.vue 鐨�
+ * scoped 鏍峰紡閲岋紝浣� <img> 宸茬粡琚尓杩涙湰缁勪欢 鈥斺�� 鐖剁粍浠剁殑 scoped 灞炴��
+ * 涓嶄細浣滅敤鍒板瓙缁勪欢鍐呴儴鍏冪礌锛岄�夋嫨鍣ㄥ尮閰嶄笉涓婏紝浜庢槸鍥剧墖鎸夊師濮嬪昂瀵告覆鏌�
+ * 锛堟暣椤垫埅鍥捐兘鍒� 1200px 瀹斤紝鎶婃秷鎭尯鎾戠垎锛夈��
+ *
+ * 缂╃暐鍥剧敤涓�涓厠鍒剁殑鍥哄畾涓婇檺锛岀偣鍑诲悗鍐嶇湅澶у浘锛�
+ * 閬垮厤闀挎埅鍥炬妸瀵硅瘽娴佹尋寰楁病娉曡銆�
+ */
+ max-width: 220px;
+ max-height: 220px;
+}
+
+.message-image-thumb {
+ max-width: 100%;
+ max-height: 100%;
+ /* 淇濇寔姣斾緥缂╂斁锛屼笉瑁佸垏涔熶笉鎷変几 */
+ object-fit: contain;
+ border-radius: 8px;
+ border: 1px solid var(--border-color);
+ display: block;
+}
+
+.img-loading {
+ width: 60px;
+ height: 60px;
+}
+
+.img-error {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 4px;
+ width: 120px;
+ height: 80px;
+ border: 1px dashed #d1d5db;
+ border-radius: 8px;
+ background: #fafafa;
+ color: var(--text-muted);
+ font-size: 11px;
+}
+
+.img-error-icon {
+ font-size: 16px;
+}
+</style>
diff --git a/src/components/CategoryPicker.vue b/src/components/CategoryPicker.vue
new file mode 100644
index 0000000..03962c3
--- /dev/null
+++ b/src/components/CategoryPicker.vue
@@ -0,0 +1,175 @@
+<template>
+ <div class="category-picker">
+ <n-select
+ v-model:value="selected"
+ size="small"
+ clearable
+ :options="options"
+ :placeholder="placeholder"
+ :disabled="disabled"
+ @update:value="handleChange"
+ />
+ <!-- 鍏佽鐜板満鏂板缓锛氫笂浼犲墠鎵嶅彂鐜版病鏈夊悎閫傚垎绫绘槸寰堝父瑙佺殑鎯呭喌锛�
+ 寮鸿揩鐢ㄦ埛鍏堝幓鍒寤哄ソ鍐嶅洖鏉ヤ細鎵撴柇鎿嶄綔娴� -->
+ <n-button size="small" quaternary :disabled="disabled" @click="showCreate = true">
+ + 鏂板缓鍒嗙被
+ </n-button>
+
+ <n-modal
+ v-model:show="showCreate"
+ preset="card"
+ title="鏂板缓鍒嗙被"
+ class="create-modal"
+ :bordered="false"
+ >
+ <n-form label-placement="top">
+ <n-form-item label="鍒嗙被鍚嶇О">
+ <n-input
+ v-model:value="newName"
+ placeholder="渚嬪锛氫骇鍝佹枃妗c�佸敭鍚庢斂绛栥�佹妧鏈鑼�"
+ maxlength="64"
+ show-count
+ @keyup.enter="handleCreate"
+ />
+ </n-form-item>
+ <n-form-item label="璇存槑锛堝彲閫夛級">
+ <n-input
+ v-model:value="newDescription"
+ placeholder="渚夸簬浠栦汉鐞嗚В杩欎釜鍒嗙被瑁呬粈涔�"
+ maxlength="255"
+ />
+ </n-form-item>
+ <n-form-item v-if="allowGlobal" label="鍙鑼冨洿">
+ <n-radio-group v-model:value="newGlobal">
+ <n-radio :value="false">浠呰嚜宸�</n-radio>
+ <n-radio :value="true">鎵�鏈夌敤鎴凤紙鍏ㄥ眬鍒嗙被锛�</n-radio>
+ </n-radio-group>
+ </n-form-item>
+ </n-form>
+ <template #footer>
+ <div class="modal-footer">
+ <n-button size="small" @click="showCreate = false">鍙栨秷</n-button>
+ <n-button size="small" type="primary" :loading="creating" @click="handleCreate">
+ 鍒涘缓
+ </n-button>
+ </div>
+ </template>
+ </n-modal>
+ </div>
+</template>
+
+<script setup>
+import { computed, onMounted, ref } from 'vue'
+import {
+ NButton,
+ NForm,
+ NFormItem,
+ NInput,
+ NModal,
+ NRadio,
+ NRadioGroup,
+ NSelect,
+ useMessage
+} from 'naive-ui'
+import { createCategory, listCategories } from '@/api/categoryApi'
+
+const props = defineProps({
+ /** 褰撳墠閫変腑鐨勫垎绫� id锛堟敮鎸� v-model:value锛� */
+ value: { type: Number, default: null },
+ /** 鏄惁鍏佽鍒涘缓鍏ㄥ眬鍒嗙被锛堜粎绠$悊鍛橀〉闈紶 true锛� */
+ allowGlobal: { type: Boolean, default: false },
+ disabled: { type: Boolean, default: false },
+ placeholder: { type: String, default: '閫夋嫨鍒嗙被锛堝彲涓嶉�夛級' }
+})
+
+const emit = defineEmits(['update:value', 'created'])
+
+const message = useMessage()
+const categories = ref([])
+const selected = ref(props.value)
+const showCreate = ref(false)
+const creating = ref(false)
+const newName = ref('')
+const newDescription = ref('')
+const newGlobal = ref(false)
+
+const options = computed(() =>
+ categories.value.map((c) => ({
+ label: c.isGlobal ? `${c.name}锛堝叏灞�锛塦 : c.name,
+ value: c.id
+ }))
+)
+
+// 鐖剁粍浠跺紓姝ヨ缃垵鍊兼椂鍚屾杩囨潵
+import { watch } from 'vue'
+watch(
+ () => props.value,
+ (v) => {
+ selected.value = v
+ }
+)
+
+onMounted(load)
+
+async function load() {
+ try {
+ categories.value = (await listCategories()) || []
+ } catch (error) {
+ message.error(error.message || '鍔犺浇鍒嗙被澶辫触')
+ }
+}
+
+function handleChange(value) {
+ emit('update:value', value ?? null)
+}
+
+async function handleCreate() {
+ const name = newName.value.trim()
+ if (!name) {
+ message.warning('璇疯緭鍏ュ垎绫诲悕绉�')
+ return
+ }
+ creating.value = true
+ try {
+ const created = await createCategory(name, newDescription.value || null, newGlobal.value)
+ categories.value = [...categories.value, created]
+ // 鏂板缓鍚庣洿鎺ラ�変腑锛岀渷鎺変竴娆℃墜鍔ㄧ偣鍑�
+ selected.value = created.id
+ emit('update:value', created.id)
+ emit('created', created)
+ message.success(`鍒嗙被銆�${created.name}銆嶅凡鍒涘缓`)
+
+ showCreate.value = false
+ newName.value = ''
+ newDescription.value = ''
+ newGlobal.value = false
+ } catch (error) {
+ message.error(error.message || '鍒涘缓澶辫触')
+ } finally {
+ creating.value = false
+ }
+}
+</script>
+
+<style scoped>
+.category-picker {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+}
+
+.category-picker :deep(.n-select) {
+ flex: 1;
+ min-width: 0;
+}
+
+.create-modal {
+ width: 440px;
+}
+
+.modal-footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: 8px;
+}
+</style>
diff --git a/src/components/ChatView.vue b/src/components/ChatView.vue
new file mode 100644
index 0000000..313ab03
--- /dev/null
+++ b/src/components/ChatView.vue
@@ -0,0 +1,1428 @@
+<template>
+ <div class="chat-view">
+ <!-- 椤堕儴鏍� -->
+ <div class="chat-header">
+ <div class="chat-header-left">
+ <n-button quaternary size="small" class="header-btn" @click="$emit('toggle-sidebar')">
+ 鈽�
+ </n-button>
+ <div class="chat-title-area">
+ <div class="chat-title">{{ chat?.title || '鏂板璇�' }}</div>
+ <div class="chat-subtitle">
+ <span>{{ modelName }}</span>
+ <span v-if="boundCollections.length" class="rag-badge">
+ 鐭ヨ瘑搴� {{ boundCollections.length }}
+ </span>
+ </div>
+ </div>
+ </div>
+
+ <div class="chat-header-right">
+ <n-button quaternary size="small" class="header-btn" @click="showSettings = true">
+ 鍙傛暟
+ </n-button>
+ <n-button quaternary size="small" class="header-btn" @click="showRag = true">
+ 鐭ヨ瘑搴�
+ </n-button>
+ </div>
+ </div>
+
+ <!-- 娑堟伅鍖� -->
+ <div ref="scrollRef" class="message-list">
+ <div v-if="!chatId" class="welcome">
+ <div class="welcome-logo">CW</div>
+ <h2 class="welcome-title">Custom-WebUI</h2>
+ <p class="welcome-sub">
+ 閫夋嫨宸︿晶鐨勫璇濓紝鎴栫偣鍑汇�屾柊瀵硅瘽銆嶅紑濮�<br />
+ 鏀寔娴佸紡杈撳嚭銆佹秷鎭垎鏀�佷互鍙婄煡璇嗗簱妫�绱㈠寮�
+ </p>
+ </div>
+
+ <template v-else>
+ <div v-if="path.length === 0 && !streaming" class="welcome">
+ <div class="welcome-logo">CW</div>
+ <h2 class="welcome-title">寮�濮嬫柊鐨勫璇�</h2>
+ <p class="welcome-sub">鍦ㄤ笅鏂硅緭鍏ヤ綘鐨勯棶棰橈紝鍥炲浼氫互娴佸紡鏂瑰紡閫愬瓧鏄剧ず</p>
+ </div>
+
+ <MessageItem
+ v-for="msg in path"
+ :key="msg.id"
+ :message="msg"
+ :is-streaming="msg.id === chatStore.streamingMessageId"
+ :branch-info="chatStore.getBranchPosition(msg)"
+ :user-initial="userInitial"
+ @switch-branch="(delta) => chatStore.switchBranch(msg, delta)"
+ @edit="(content) => handleEdit(msg, content)"
+ @regenerate="() => handleRegenerate(msg)"
+ @delete="() => handleDelete(msg)"
+ />
+ </template>
+ </div>
+
+ <!-- 閿欒鎻愮ず -->
+ <div v-if="chatStore.streamError" class="stream-error">
+ <span>{{ chatStore.streamError }}</span>
+ <button class="error-close" @click="chatStore.streamError = ''">脳</button>
+ </div>
+
+ <!-- 杈撳叆鍖� -->
+ <div class="composer">
+ <div class="composer-inner">
+ <!-- 寰呭彂閫佺殑鍥剧墖锛氭樉绀虹缉鐣ュ浘涓庤瘑鍒嚭鐨勬枃瀛楋紝鍙戦�佸墠鍙垹 -->
+ <div v-if="pendingImages.length" class="pending-images">
+ <div v-for="img in pendingImages" :key="img.key" class="pending-image">
+ <img :src="img.previewUrl" class="pending-thumb" alt="寰呭彂閫佸浘鐗�" />
+ <div class="pending-info">
+ <div class="pending-name">{{ img.filename }}</div>
+ <div class="pending-status" :class="img.status">
+ <template v-if="img.status === 'ocr'">璇嗗埆涓�� {{ img.progress }}%</template>
+ <template v-else-if="img.status === 'done'">
+ 宸茶瘑鍒� {{ img.text.length }} 瀛�
+ </template>
+ <template v-else-if="img.status === 'empty'">
+ 鏈瘑鍒埌鏂囧瓧锛堜粛鍙綔涓哄浘鐗囧彂閫侊級
+ </template>
+ <template v-else>璇嗗埆澶辫触锛歿{ img.error }}</template>
+ </div>
+ </div>
+ <button class="pending-remove" title="绉婚櫎" @click="removePendingImage(img.key)">脳</button>
+ </div>
+ </div>
+
+ <n-input
+ ref="inputRef"
+ v-model:value="draft"
+ type="textarea"
+ :autosize="{ minRows: 1, maxRows: 8 }"
+ :placeholder="composerPlaceholder"
+ :disabled="!chatId"
+ @keydown="handleKeydown"
+ @paste="handlePaste"
+ />
+
+ <!-- 闅愯棌鐨勬枃浠堕�夋嫨妗嗭細accept 鍙垪鍥剧墖绫诲瀷 -->
+ <input
+ ref="imageInputRef"
+ type="file"
+ class="hidden-image-input"
+ multiple
+ :accept="imageAccept"
+ @change="handleImageSelect"
+ />
+
+ <div class="composer-actions">
+ <label class="rag-toggle">
+ <n-switch v-model:value="useRag" size="small" :disabled="!hasRag" />
+ <span class="rag-toggle-label" :class="{ disabled: !hasRag }">
+ {{ hasRag ? '鍚敤鐭ヨ瘑搴�' : '鏈粦瀹氱煡璇嗗簱' }}
+ </span>
+ </label>
+
+ <div class="composer-buttons">
+ <n-button
+ size="small"
+ :disabled="!chatId || chatStore.streaming"
+ :loading="pendingImages.some((i) => i.status === 'ocr')"
+ title="涓婁紶鍥剧墖锛岃瘑鍒叾涓枃瀛楀悗涓�骞跺璇�"
+ @click="pickImage"
+ >
+ 鍥剧墖
+ </n-button>
+ <n-button
+ v-if="chatStore.streaming"
+ size="small"
+ @click="chatStore.stopStreaming()"
+ >
+ 鍋滄鐢熸垚
+ </n-button>
+ <n-button
+ type="primary"
+ size="small"
+ :disabled="!canSend"
+ :loading="chatStore.streaming"
+ @click="handleSend"
+ >
+ 鍙戦��
+ </n-button>
+ </div>
+ </div>
+ </div>
+ <div class="composer-hint">
+ Enter 鍙戦�侊紝Shift + Enter 鎹㈣ 路 鍙洿鎺ョ矘璐存埅鍥撅紝鎴栫偣銆屽浘鐗囥�嶉�夋嫨鏂囦欢
+ </div>
+ </div>
+
+ <!-- 妯″瀷鍙傛暟鎶藉眽 -->
+ <n-drawer v-model:show="showSettings" :width="400" placement="right">
+ <n-drawer-content title="妯″瀷鍙傛暟" closable>
+ <n-form label-placement="top">
+ <n-form-item label="妯″瀷鍚嶇О">
+ <n-input v-model:value="metaForm.modelName" placeholder="鐣欑┖浣跨敤鍚庣榛樿妯″瀷" />
+ </n-form-item>
+ <n-form-item :label="`娓╁害 temperature锛�${metaForm.temperature}`">
+ <n-slider v-model:value="metaForm.temperature" :min="0" :max="2" :step="0.1" />
+ </n-form-item>
+ <n-form-item :label="`鏍搁噰鏍� top_p锛�${metaForm.topP}`">
+ <n-slider v-model:value="metaForm.topP" :min="0" :max="1" :step="0.05" />
+ </n-form-item>
+ <n-form-item label="涓婁笅鏂囩獥鍙� num_ctx">
+ <n-input-number v-model:value="metaForm.numCtx" :min="512" :max="131072" :step="512" />
+ </n-form-item>
+ <n-form-item label="绯荤粺鎻愮ず璇�">
+ <n-input
+ v-model:value="metaForm.systemPrompt"
+ type="textarea"
+ :autosize="{ minRows: 4, maxRows: 10 }"
+ placeholder="渚嬪锛氫綘鏄竴涓弗璋ㄧ殑鎶�鏈姪鎵嬶紝鍥炵瓟灏介噺绠�娲併��"
+ />
+ </n-form-item>
+ </n-form>
+ <template #footer>
+ <n-button type="primary" :loading="savingMeta" @click="saveMeta">淇濆瓨鍙傛暟</n-button>
+ </template>
+ </n-drawer-content>
+ </n-drawer>
+
+ <!-- 鐭ヨ瘑搴撴娊灞� -->
+ <n-drawer v-model:show="showRag" :width="520" placement="right">
+ <n-drawer-content title="鐭ヨ瘑搴撹缃�" closable>
+ <n-alert v-if="!ragEnabled" type="warning" :bordered="false" class="rag-alert">
+ 鍚庣閰嶇疆涓� RAG 鍔熻兘宸插叧闂紙webui.rag.enabled=false锛夛紝妫�绱笉浼氱敓鏁堛��
+ </n-alert>
+ <n-alert v-else-if="!ragAvailable" type="warning" :bordered="false" class="rag-alert">
+ RAG 鏈嶅姟褰撳墠涓嶅彲鐢紙{{ ragBaseUrl }}锛夈�傝鍚姩 Python 鏈嶅姟锛�<br />
+ <code>cd rag-service && uvicorn main:app --host 0.0.0.0 --port 8000</code>
+ </n-alert>
+
+ <p class="rag-section-title">涓婁紶鏂版枃妗�</p>
+ <FileUpload
+ :chat-id="chatId"
+ @uploaded="handleUploaded"
+ @category-created="handleCategoryCreated"
+ />
+
+ <!--
+ 鏁寸被缁戝畾鍖猴細鎶娿�岀粦瀹氱煡璇嗗簱銆嶄粠閫愪釜鍕鹃�夊彉鎴愪竴娆$偣鍑汇��
+ 缁戠殑鏄垎绫� id锛屽悗绔绱㈡椂鎵嶅睍寮� 鈥斺�� 涔嬪悗寰�鍒嗙被閲屾柊澧炴枃妗o紝
+ 杩欎釜浼氳瘽浼氳嚜鍔ㄦ绱㈠埌锛屼笉鐢ㄥ洖鏉ラ噸鏂扮粦瀹氥��
+ -->
+ <p class="rag-section-title">
+ 鍒嗙被缁戝畾
+ <span class="section-hint">涓�娆$粦瀹氭暣涓垎绫�</span>
+ <n-button text size="tiny" class="section-refresh" @click="refreshRagState(props.chatId)">
+ 鍒锋柊
+ </n-button>
+ </p>
+ <div v-if="categories.length === 0" class="empty-hint">
+ 杩樻病鏈夊垎绫汇�備笂浼犳枃妗f椂鍙�夋嫨鎴栨柊寤哄垎绫伙紝涔嬪悗鍗冲彲鏁寸被缁戝畾銆�
+ </div>
+ <div v-for="category in categories" v-else :key="category.id" class="category-row">
+ <div class="category-row-main">
+ <div class="category-name">
+ {{ category.name }}
+ <span v-if="category.isGlobal" class="global-badge">鍏ㄥ眬</span>
+ </div>
+ <div class="category-meta">
+ {{ category.ingestedCount }}/{{ category.fileCount }} 绡囧凡鍏ュ簱
+ <span v-if="category.ingestedCount === 0" class="file-status pending">
+ 路 鏃犲凡鍏ュ簱鏂囨。锛岀粦瀹氬悗妫�绱笉鍒板唴瀹�
+ </span>
+ </div>
+ </div>
+ <n-button
+ size="tiny"
+ :disabled="category.ingestedCount === 0"
+ :type="isCategoryBound(category.id) ? 'primary' : 'default'"
+ :loading="categoryBindingId === category.id"
+ @click="toggleCategoryBinding(category)"
+ >
+ {{ isCategoryBound(category.id) ? '宸茬粦瀹�' : '缁戝畾鏁寸被' }}
+ </n-button>
+ </div>
+
+ <p class="rag-section-title">
+ 鎴戠殑鐭ヨ瘑搴�
+ <span class="section-hint">涔熷彲鍗曠嫭缁戝畾鏌愮瘒</span>
+ </p>
+ <div v-if="files.length === 0" class="empty-hint">杩樻病鏈変笂浼犱换浣曟枃妗�</div>
+ <div v-for="file in files" :key="file.id" class="file-row">
+ <div class="file-row-main">
+ <div class="file-name">
+ {{ file.filename }}
+ <!-- 鍏ㄥ眬鐭ヨ瘑搴撶敱绠$悊鍛樼淮鎶わ紝鏅�氱敤鎴峰彧鑳界粦瀹氫娇鐢� -->
+ <span v-if="file.isGlobal" class="global-badge">鍏ㄥ眬</span>
+ </div>
+ <div class="file-meta">
+ {{ formatSize(file.fileSize) }}
+ <span v-if="file.categoryName" class="file-category">路 {{ file.categoryName }}</span>
+ <span v-if="file.ingested" class="file-status ok">
+ 路 宸插叆搴� {{ file.chunkCount }} 鍧�
+ </span>
+ <span v-else-if="file.ingestMessage" class="file-status fail">
+ 路 {{ file.ingestMessage }}
+ </span>
+ <span v-else class="file-status pending">路 鏈悜閲忓寲</span>
+ </div>
+ </div>
+ <div class="file-row-actions">
+ <n-button
+ v-if="!file.ingested && file.canManage"
+ size="tiny"
+ :loading="ingestingId === file.id"
+ @click="handleIngest(file)"
+ >
+ 鍚戦噺鍖�
+ </n-button>
+ <n-button
+ v-if="file.collectionName"
+ size="tiny"
+ :type="isCollectionActive(file.collectionName) ? 'primary' : 'default'"
+ @click="toggleBinding(file.collectionName)"
+ >
+ {{ isCollectionActive(file.collectionName) ? '宸茬粦瀹�' : '缁戝畾' }}
+ </n-button>
+ <n-button
+ v-if="file.canManage"
+ size="tiny"
+ type="error"
+ quaternary
+ @click="handleDeleteFile(file)"
+ >
+ 鍒犻櫎
+ </n-button>
+ </div>
+ </div>
+
+ <template #footer>
+ <div class="rag-footer">
+ <span class="text-secondary">
+ 宸茬粦瀹� {{ boundCollections.length }} 涓煡璇嗗簱锛岃亰澶╂椂浼氳嚜鍔ㄦ绱�
+ </span>
+ </div>
+ </template>
+ </n-drawer-content>
+ </n-drawer>
+ </div>
+</template>
+
+<script setup>
+import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
+import {
+ NAlert,
+ NButton,
+ NDrawer,
+ NDrawerContent,
+ NForm,
+ NFormItem,
+ NInput,
+ NInputNumber,
+ NSlider,
+ NSwitch,
+ useDialog,
+ useMessage
+} from 'naive-ui'
+import MessageItem from './MessageItem.vue'
+import FileUpload from './FileUpload.vue'
+import {
+ bindCategory,
+ listCategories,
+ listCategoryBindings
+} from '@/api/categoryApi'
+import { IMAGE_EXTENSIONS, recognizeImage, storeAttachmentText } from '@/api/fileApi'
+import { useChatStore } from '@/stores/chatStore'
+import { useAuthStore } from '@/stores/authStore'
+import {
+ bindCollections,
+ deleteFile,
+ ingestFile,
+ listBindings,
+ listFiles,
+ ragHealth
+} from '@/api/fileApi'
+
+const emit = defineEmits(['toggle-sidebar'])
+
+const props = defineProps({
+ chatId: { type: Number, default: null }
+})
+
+const chatStore = useChatStore()
+const auth = useAuthStore()
+const message = useMessage()
+const dialog = useDialog()
+
+const draft = ref('')
+const useRag = ref(true)
+const scrollRef = ref(null)
+const inputRef = ref(null)
+
+const showSettings = ref(false)
+const showRag = ref(false)
+const savingMeta = ref(false)
+
+const files = ref([])
+const boundCollections = ref([])
+const ingestingId = ref(null)
+/** 鍙鍒嗙被锛堝甫 fileCount / ingestedCount / collectionNames锛� */
+const categories = ref([])
+/** 璇ヤ細璇濆凡缁戝畾鐨勫垎绫� id */
+const boundCategoryIds = ref([])
+/** 姝e湪缁戝畾/瑙g粦鐨勫垎绫� id锛岀敤浜庢寜閽� loading */
+const categoryBindingId = ref(null)
+
+const ragEnabled = ref(true)
+const ragAvailable = ref(true)
+const ragBaseUrl = ref('')
+
+const chat = computed(() => chatStore.activeChat)
+const path = computed(() => chatStore.path)
+const userInitial = computed(() => (auth.displayName || 'U').charAt(0).toUpperCase())
+
+/**
+ * 褰撳墠鏄惁姝e湪娴佸紡鐢熸垚銆�
+ *
+ * 妯℃澘閲岀敤 `streaming` 鑰屼笉鏄洿鎺ュ啓 `chatStore.streaming`锛�
+ * 涓�鏄彲璇绘�э紝浜屾槸灏嗘潵鑻ヨ鍔犮�屽凡鍙戦�佷絾棣栦釜 token 鏈埌銆嶈繖绫绘淳鐢熺姸鎬侊紝
+ * 鍙渶鏀硅繖涓�澶勩��
+ *
+ * 娉ㄦ剰锛氳繖涓� computed 鏄繀椤荤殑 鈥斺�� 涔嬪墠妯℃澘寮曠敤浜� `streaming` 鍗存病瀹氫箟锛�
+ * Vue 鍙細鍦ㄦ帶鍒跺彴鎵撲竴鏉� warning锛岄〉闈㈢収甯告覆鏌撲絾璇ユ潯浠舵亽涓�
+ * undefined锛坒alsy锛夛紝琛ㄧ幇涓虹┖浼氳瘽鏃舵杩庤涓庢秷鎭尯鍚屾椂鍑虹幇銆�
+ */
+const streaming = computed(() => chatStore.streaming)
+
+/**
+ * 褰撳墠浼氳瘽銆屽疄闄呯敓鏁堛�嶇殑鍏ㄩ儴闆嗗悎 = 鍗曠瘒缁戝畾鐨勯泦鍚� 鈭� 宸茬粦瀹氬垎绫诲睍寮�鍑虹殑闆嗗悎銆�
+ *
+ * 杩欎釜璁$畻灞炴�ф槸淇竴涓弗閲� bug 鐨勫叧閿�備箣鍓嶇姸鎬佹槸鍒嗘暎鐨勶細
+ * - hasRag 鍙湅 boundCollections锛堝崟绡囩粦瀹氾級
+ * - 鍒嗙被缁戝畾鍙啓鍦� boundCategoryIds 閲�
+ * 浜庢槸銆岀粦瀹氭暣绫汇�嶄箣鍚� hasRag 浠嶄负 false 鈫�
+ * 1) 搴曢儴鏄剧ず銆屾湭缁戝畾鐭ヨ瘑搴撱��
+ * 2) 鍙戦�佹秷鎭椂 useRag 琚畻鎴� false锛屽悗绔�**鏍规湰娌″仛妫�绱�**锛�
+ * 鍥炵瓟鑷劧涓嶅紩鐢ㄧ煡璇嗗簱
+ *
+ * 鏍瑰洜鏄妸銆岀敤鎴风粦浜嗕粈涔堛�嶅拰銆屽疄闄呯敓鏁堜粈涔堛�嶆贩涓轰竴璋堛��
+ * 鐜板湪缁熶竴鐢辫繖閲屾帹瀵硷紝涓ゅ缁戝畾鏂瑰紡閮借鐩栵紝涓嶅啀鏈夐仐婕忋��
+ */
+const effectiveBoundCollections = computed(() => {
+ const set = new Set(boundCollections.value)
+ for (const cat of categories.value) {
+ if (!boundCategoryIds.value.includes(cat.id)) {
+ continue
+ }
+ for (const name of cat.collectionNames || []) {
+ set.add(name)
+ }
+ }
+ return [...set]
+})
+
+// ---------------- 鍥剧墖涓婁紶涓� OCR ----------------
+
+/**
+ * 寰呭彂閫佺殑鍥剧墖銆�
+ *
+ * 姣忛」褰㈠ { key, filename, previewUrl, status, progress, text, fileId, error }
+ * status: ocr锛堣瘑鍒腑锛�/ done / empty锛堟病璇嗗埆鍒板瓧锛�/ failed
+ */
+const pendingImages = ref([])
+const imageInputRef = ref(null)
+
+const imageAccept = IMAGE_EXTENSIONS.map((e) => `.${e}`).join(',')
+
+function pickImage() {
+ if (!props.chatId || chatStore.streaming) return
+ imageInputRef.value?.click()
+}
+
+function handleImageSelect(event) {
+ const files = Array.from(event.target.files || [])
+ // 娓呯┖ value锛屽惁鍒欒繛缁�夊悓涓�涓枃浠朵笉浼氳Е鍙� change
+ event.target.value = ''
+ uploadImages(files)
+}
+
+async function uploadImages(files) {
+ if (files.length === 0) return
+
+ for (const file of files) {
+ const ext = file.name.split('.').pop()?.toLowerCase() || ''
+ if (!IMAGE_EXTENSIONS.includes(ext)) {
+ message.error(`${file.name}锛氫笉鏄敮鎸佺殑鍥剧墖绫诲瀷锛�${IMAGE_EXTENSIONS.join('/')}锛塦)
+ continue
+ }
+ if (file.size > 20 * 1024 * 1024) {
+ message.error(`${file.name}锛氬浘鐗囪秴杩� 20MB`)
+ continue
+ }
+
+ // 鏈湴棰勮锛歄bjectURL 涓嶅崰鍐呭瓨锛屽垹闄ゆ椂璁板緱 revoke
+ const item = reactive({
+ key: `${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
+ filename: file.name,
+ previewUrl: URL.createObjectURL(file),
+ status: 'ocr',
+ progress: 0,
+ text: '',
+ fileId: null,
+ error: ''
+ })
+ pendingImages.value.push(item)
+
+ try {
+ const result = await recognizeImage(file, props.chatId, (percent) => {
+ item.progress = percent
+ })
+ item.fileId = result.fileId
+ item.text = result.text || ''
+ item.status = item.text.trim() ? 'done' : 'empty'
+
+ if (item.status === 'empty') {
+ // 涓嶆槸閿欒锛氱敤鎴峰彲鑳藉氨鏄兂鍙戝紶鍥俱�傝娓呮瀹冧笉浼氳妯″瀷"鐪嬫噦"鍗冲彲
+ message.info(`${file.name} 鏈瘑鍒埌鏂囧瓧锛屽浘鐗囦粛浼氬彂鍑猴紝浣嗘ā鍨嬪彧鑳界湅鍒版枃浠跺悕`)
+ }
+ } catch (error) {
+ item.status = 'failed'
+ item.error = error.message || '璇嗗埆澶辫触'
+ message.error(`${file.name}锛�${item.error}`)
+ }
+ }
+}
+
+/**
+ * 浠庡壀璐存澘浜嬩欢涓彇鍑哄浘鐗囨枃浠躲��
+ *
+ * 涓轰粈涔堣閬嶅巻 items 鑰屼笉鑳藉彧鐪� items[0]锛�
+ * 浠庣綉椤靛鍒跺唴瀹规椂锛宑lipboardData 閲屽線寰�鍚屾椂鏈� text/html銆乼ext/plain
+ * 鍜� image/png銆傚彧鍙栫涓�椤瑰彲鑳芥嬁鍒� HTML 鑰屼笉鏄浘鐗囷紝
+ * 瀵艰嚧銆屾槑鏄庡鍒剁殑鍥剧墖鍗寸矘鍑轰簡婧愮爜銆嶃��
+ */
+function extractImageFiles(event) {
+ const items = event.clipboardData?.items
+ if (!items) return []
+ const files = []
+ for (const item of items) {
+ if (item.kind === 'file' && item.type.startsWith('image/')) {
+ const file = item.getAsFile()
+ if (file) files.push(file)
+ }
+ }
+ return files
+}
+
+/**
+ * 绮樿创澶勭悊銆�
+ *
+ * 鍙嫤銆屽壀璐存澘閲岀‘瀹炴湁鍥剧墖銆嶇殑鎯呭喌锛涚函鏂囨湰绮樿创浜ょ粰娴忚鍣ㄩ粯璁よ涓猴紝
+ * 鍚﹀垯浼氱牬鍧忔甯哥矘璐存枃瀛椼�佷互鍙婂甫鏍煎紡鏂囨湰鐨勭矘璐淬��
+ */
+/**
+ * 鏈绮樿创鏄惁宸茶缁勪欢绾у鐞嗐��
+ *
+ * 鐢ㄥ畠鑰屼笉鏄椂闂寸獥鍙e幓閲嶏細鏃堕棿绐楀彛浼氳浼ゃ��300ms 鍐呰繛缁矘璐翠袱娆″浘鐗囥�嶏紝
+ * 鑰岃繖绉嶇簿纭爣璁板彧鍚冩帀鍚屼竴涓簨浠剁殑閲嶅鎶曢�掞紝涓嶄細褰卞搷涓嬩竴娆$湡瀹炵矘璐淬��
+ */
+let pasteConsumedByComposer = false
+
+function handlePaste(event) {
+ const files = extractImageFiles(event)
+ if (files.length === 0) {
+ // 鍓创鏉块噷鏈夋枃瀛椾篃鏈夊浘鐗囨椂锛堜粠缃戦〉澶嶅埗锛夛紝鏂囧瓧鐓у父鎻掑叆锛屽浘鐗囬澶栨敹涓�
+ return
+ }
+
+ // 闃绘榛樿琛屼负锛岄伩鍏嶆妸鍥剧墖鐨� html/鏂囦欢鍚嶅綋鏂囨湰濉炶繘杈撳叆妗�
+ event.preventDefault()
+ // 鏍囪鏈绮樿创宸茶澶勭悊锛岄伩鍏� document 灞傜殑鍏滃簳鐩戝惉閲嶅鏀朵竴娆�
+ pasteConsumedByComposer = true
+
+ if (!props.chatId) {
+ message.warning('璇峰厛閫夋嫨鎴栨柊寤轰竴涓璇�')
+ return
+ }
+ if (chatStore.streaming) {
+ message.warning('姝e湪鐢熸垚鍥炲锛岃绋嶅�欏啀绮樿创鍥剧墖')
+ return
+ }
+
+ // 鍓创鏉块噷鐨勫浘鐗囧線寰�娌℃湁鏂囦欢鍚嶏紙鎴浘銆佸鍒剁殑鍥撅級锛岀粰涓彲璇荤殑榛樿鍚嶏紝
+ // 鍚﹀垯銆屾垜鐨勭煡璇嗗簱銆嶉噷浼氬嚭鐜颁竴鍫嗘棤鍚嶇殑 png
+ const named = files.map((f, i) =>
+ f.name && f.name !== 'image.png'
+ ? f
+ : new File([f], `绮樿创鍥剧墖_${timestampName()}${files.length > 1 ? `_${i + 1}` : ''}.png`, {
+ type: f.type || 'image/png'
+ })
+ )
+
+ uploadImages(named)
+}
+
+/** 鐢熸垚鐢ㄤ簬鏂囦欢鍚嶇殑鐭椂闂存埑锛屽 20261001_143012 */
+function timestampName() {
+ const d = new Date()
+ const pad = (n) => String(n).padStart(2, '0')
+ return (
+ `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}` +
+ `_${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`
+ )
+}
+
+/**
+ * 鏂囨。绾х矘璐村厹搴曘��
+ *
+ * 鍙湪銆岀矘璐村彂鐢熺殑浣嶇疆涓嶅湪浠讳綍杈撳叆妗嗛噷銆嶆椂鎺ョ 鈥斺�� 鐢ㄦ埛鐐逛簡椤甸潰绌虹櫧澶勫啀绮樿创
+ * 涔熻兘鏀跺埌鍥撅紝绗﹀悎鐩磋銆傝嫢鐒︾偣宸插湪杈撳叆妗嗗唴锛岀敱涓婇潰鐨� handlePaste 澶勭悊锛�
+ * 杩欓噷鐩存帴璺宠繃锛屽惁鍒欎細閲嶅鏀跺浘銆�
+ */
+function handleDocumentPaste(event) {
+ // 鍚屼竴涓簨浠跺凡鐢辩粍浠剁骇澶勭悊杩囷紝娑堣垂鎺夋爣璁板苟璺宠繃
+ if (pasteConsumedByComposer) {
+ pasteConsumedByComposer = false
+ return
+ }
+
+ // 鐒︾偣鍦ㄨ緭鍏ョ被鍏冪礌閲屾椂浜ょ粰瀹冧滑鑷繁澶勭悊
+ const el = document.activeElement
+ const tag = el?.tagName?.toLowerCase()
+ if (tag === 'input' || tag === 'textarea' || el?.isContentEditable) return
+
+ const files = extractImageFiles(event)
+ if (files.length === 0) return
+ event.preventDefault()
+ uploadImages(files.map((f) => new File([f], `绮樿创鍥剧墖_${timestampName()}.png`, { type: f.type || 'image/png' })))
+}
+
+function removePendingImage(key) {
+ const idx = pendingImages.value.findIndex((i) => i.key === key)
+ if (idx === -1) return
+ // 閲婃斁 ObjectURL锛屽惁鍒欓暱鏃堕棿浣跨敤浼氭寔缁崰鐢ㄥ唴瀛�
+ URL.revokeObjectURL(pendingImages.value[idx].previewUrl)
+ pendingImages.value.splice(idx, 1)
+}
+
+async function clearPendingImages() {
+ for (const img of pendingImages.value) {
+ URL.revokeObjectURL(img.previewUrl)
+ }
+ pendingImages.value = []
+}
+
+/** 鏄惁鏈夊彲鐢ㄤ簬妫�绱㈢殑鐭ヨ瘑搴擄紙鍗曠瘒鎴栨暣绫婚兘绠楋級 */
+const hasRag = computed(() => effectiveBoundCollections.value.length > 0)
+
+/** 鏌愮瘒鏂囨。锛堟寜闆嗗悎鍚嶏級褰撳墠鏄惁澶勪簬宸茬粦瀹�/鐢熸晥鐘舵�� */
+function isCollectionActive(collectionName) {
+ return effectiveBoundCollections.value.includes(collectionName)
+}
+const canSend = computed(() => {
+ if (!props.chatId || streaming.value) return false
+ // 鍏佽銆屽彧鍙戝浘鐗囦笉鎵撳瓧銆嶏細涓婁紶浜嗗浘灏辫兘鍙�
+ return draft.value.trim().length > 0 || pendingImages.value.length > 0
+})
+
+const modelName = computed(() => {
+ const meta = chat.value?.meta
+ return meta?.modelName || '榛樿妯″瀷'
+})
+
+const composerPlaceholder = computed(() =>
+ props.chatId ? '杈撳叆娑堟伅鈥�' : '璇峰厛鏂板缓鎴栭�夋嫨涓�涓璇�'
+)
+
+const metaForm = ref({
+ modelName: '',
+ temperature: 0.7,
+ topP: 0.9,
+ numCtx: 8192,
+ systemPrompt: ''
+})
+
+// ---------------- 浼氳瘽鍒囨崲 ----------------
+
+watch(
+ () => props.chatId,
+ async (chatId) => {
+ if (!chatId) {
+ chatStore.resetView()
+ files.value = []
+ boundCollections.value = []
+ boundCategoryIds.value = []
+ // 娉ㄦ剰锛�**涓嶈兘鍦ㄨ繖閲� return**銆�
+ // 娌℃湁閫変腑浼氳瘽鏃讹紙鐢ㄦ埛鍒氳繘 /c锛屾垨鍒犳帀浜嗗綋鍓嶄細璇濓級锛�
+ // 鍒嗙被鍒楄〃涓庢枃浠跺垪琛ㄤ粛鐒跺簲璇ユ樉绀� 鈥斺�� 鍚﹀垯鐢ㄦ埛鏂板缓浜嗗垎绫汇��
+ // 鎵撳紑鐭ヨ瘑搴撳嵈浠�涔堥兘鐪嬩笉鍒帮紝浼氫互涓哄垎绫绘病寤烘垚鍔熴��
+ // 鍙槸姝ゆ椂娌℃湁銆屽凡缁戝畾銆嶇姸鎬佸彲鏍囪鑰屽凡銆�
+ await refreshRagState(null)
+ return
+ }
+
+ // 鍒囦細璇濆墠鍏堟妸鍙兘杩樺湪璺戠殑娴佷腑鏂帀銆�
+ // 杩欐槸銆屽彂閫佹寜閽崱姝汇�嶇殑鍏滃簳鎭㈠鎵嬫锛氫竴鏃� streaming 鍥犱换浣曠珵鎬�
+ // 娈嬬暀鍦� true锛屽垏涓�娆′細璇濆嵆鍙仮澶嶏紝涓嶉渶瑕佸埛鏂伴〉闈€��
+ chatStore.stopStreaming()
+
+ try {
+ // 涓嶄繚鐣欎笂涓�涓細璇濈殑鍒嗘敮閫夋嫨锛岄伩鍏� id 澶嶇敤瀵艰嚧鐨勯敊涔�
+ await chatStore.loadMessages(chatId, false)
+ syncMetaForm()
+ await refreshRagState(chatId)
+ scrollToBottom()
+ } catch (error) {
+ message.error(error.message || '鍔犺浇娑堟伅澶辫触')
+ }
+ },
+ { immediate: true }
+)
+
+// 鏂板唴瀹瑰埌杈炬椂鑷姩婊氬埌搴曢儴
+watch(
+ () => path.value.map((item) => item.content).join('|'),
+ () => scrollToBottom()
+)
+
+watch(
+ () => chatStore.streaming,
+ (streaming) => {
+ if (!streaming) scrollToBottom()
+ }
+)
+
+function syncMetaForm() {
+ const meta = chat.value?.meta || {}
+ metaForm.value = {
+ modelName: meta.modelName || '',
+ temperature: meta.temperature ?? 0.7,
+ topP: meta.topP ?? 0.9,
+ numCtx: meta.numCtx ?? 8192,
+ systemPrompt: meta.systemPrompt || ''
+ }
+}
+
+/**
+ * 鍔犺浇鐭ヨ瘑搴撶浉鍏崇姸鎬併��
+ *
+ * @param chatId 鍙负 null 鈥斺�� 鏈�変腑浼氳瘽鏃讹紝鍒嗙被涓庢枃浠跺垪琛ㄤ粛闇�姝e父灞曠ず锛�
+ * 鍙槸鏃犳硶鏍囪銆屽凡缁戝畾銆嶇姸鎬併��
+ */
+async function refreshRagState(chatId) {
+ try {
+ const health = await ragHealth()
+ ragEnabled.value = health.enabled !== false
+ ragAvailable.value = health.available !== false
+ ragBaseUrl.value = health.baseUrl || ''
+ } catch {
+ // 鍋ュ悍妫�鏌ュけ璐ヤ笉闃绘柇椤甸潰锛屾寜銆屼笉鍙敤銆嶆樉绀�
+ ragAvailable.value = false
+ }
+
+ try {
+ // chatId 涓虹┖鏃惰烦杩囦緷璧栦細璇濈殑璇锋眰锛堜細 400/404锛夛紝浣嗕粛瑕佹嬁鍒嗙被涓庢枃浠�
+ const [fileList, bindings, categoryList, categoryBindings] = await Promise.all([
+ listFiles(null),
+ chatId != null ? listBindings(chatId) : Promise.resolve([]),
+ listCategories(chatId),
+ chatId != null ? listCategoryBindings(chatId) : Promise.resolve([])
+ ])
+ files.value = fileList || []
+ boundCollections.value = bindings || []
+ categories.value = categoryList || []
+ boundCategoryIds.value = categoryBindings || []
+ // useRag 鏄�岀敤鎴锋槸鍚﹀笇鏈涘惎鐢ㄦ绱€�嶇殑鎰忓浘寮�鍏筹紝
+ // 鏄惁鐪熺殑鏈夌煡璇嗗簱鍙敤鐢� hasRag 鎺ㄥ锛屼笉鍐嶆墜宸ュ悓姝ワ紝閬垮厤涓ゅ鐘舵�佹紓绉�
+ if (hasRag.value) {
+ useRag.value = true
+ }
+ } catch (error) {
+ message.error(error.message || '鍔犺浇鐭ヨ瘑搴撲俊鎭け璐�')
+ }
+}
+
+/** 璇ュ垎绫绘槸鍚﹀凡缁戝畾鍒板綋鍓嶄細璇� */
+function isCategoryBound(categoryId) {
+ return boundCategoryIds.value.includes(categoryId)
+}
+
+/**
+ * 鏁寸被缁戝畾 / 瑙g粦銆�
+ *
+ * 鎻愪氦鐨勬槸**鍒嗙被 id**锛屾绱㈡椂鐢卞悗绔睍寮�鎴愰泦鍚� 鈥斺��
+ * 鍥犳涔嬪悗寰�鍒嗙被閲屾柊澧炴枃妗d細鑷姩鐢熸晥锛屼笉闇�瑕佸洖鍒拌繖閲岄噸鏂扮粦瀹氥��
+ */
+async function toggleCategoryBinding(category) {
+ if (props.chatId == null) {
+ message.warning('璇峰厛閫夋嫨鎴栨柊寤轰竴涓璇濓紝鍐嶇粦瀹氱煡璇嗗簱鍒嗙被')
+ return
+ }
+ const bind = !isCategoryBound(category.id)
+ categoryBindingId.value = category.id
+ try {
+ boundCategoryIds.value = (await bindCategory(props.chatId, category.id, bind)) || []
+ // 缁戝畾鍚庤嚜鍔ㄦ墦寮�妫�绱㈠紑鍏筹細鐢ㄦ埛鍒氱粦瀹氱煡璇嗗簱锛屾剰鍥炬樉鐒舵槸銆岃鐢ㄥ畠銆�
+ if (hasRag.value) {
+ useRag.value = true
+ }
+
+ if (bind) {
+ // 鎻愮ず閲岀偣鏄庛�屾柊澧炴枃妗d細鑷姩鐢熸晥銆嶏紝杩欐槸鏁寸被缁戝畾鐩稿閫愪釜缁戝畾鐨勬牳蹇冧紭鍔�
+ message.success(
+ `宸茬粦瀹氬垎绫汇��${category.name}銆嶏紙${category.ingestedCount} 绡囧凡鍏ュ簱锛夛紝` +
+ '浠ュ悗寰�璇ュ垎绫绘柊澧炴枃妗d細鑷姩鍙備笌妫�绱�'
+ )
+ } else {
+ message.success(`宸茶В缁戝垎绫汇��${category.name}銆峘)
+ }
+ } catch (error) {
+ message.error(error.message || '鎿嶄綔澶辫触')
+ } finally {
+ categoryBindingId.value = null
+ }
+}
+
+// ---------------- 鍙戦�� ----------------
+
+function handleKeydown(event) {
+ // Enter 鍙戦�侊紝Shift+Enter 鎹㈣锛涜緭鍏ユ硶缁勫悎涓殑 Enter 涓嶅簲瑙﹀彂鍙戦��
+ if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
+ event.preventDefault()
+ handleSend()
+ }
+}
+
+async function handleSend() {
+ const content = draft.value.trim()
+ const hasImages = pendingImages.value.length > 0
+ if ((!content && !hasImages) || !props.chatId || chatStore.streaming) return
+
+ // 鍏堟竻绌鸿緭鍏ユ涓庡緟鍙戦�佸浘鐗囷紝璁╃敤鎴疯兘绔嬪嵆缁х画鎵撳瓧 / 缁х画閫夊浘
+ draft.value = ''
+
+ // 鍥剧墖鏁版嵁鍏堝彇涓嬪揩鐓э細sendMessage 浼氱珛鍒绘妸娑堟伅涔愯娓叉煋杩涙秷鎭爲锛�
+ // 棰勮鍖哄氨娌″繀瑕佺户缁崰鐫�浜嗐��
+ //
+ // 娉ㄦ剰涓嶈兘绛� sendMessage 杩斿洖鍐嶆竻 鈥斺�� 閭h绛夋暣娈靛洖绛旂敓鎴愬畬
+ // 锛堝疄娴� 9 绉掍互涓婏級锛屾湡闂撮瑙堝尯涓�鐩存寕鐫�銆屽緟鍙戦�佸浘鐗囥�嶏紝
+ // 鐢ㄦ埛浼氫互涓烘病鍙戝嚭鍘昏�岄噸澶嶅彂閫併��
+ const imageText = pendingImages.value
+ .map((i) => i.text)
+ .filter((t) => t && t.trim())
+ .join('\n\n')
+ const imageFileIds = pendingImages.value
+ .map((i) => i.fileId)
+ .filter((id) => id != null)
+
+ await clearPendingImages()
+
+ // 闀挎枃鏈厛鏆傚瓨鎹㈢煭 id锛歋SE 鏄� GET锛屽弬鏁板彧鑳借蛋 query string锛�
+ // 鑰屼腑鏂� URL 缂栫爜绾� 9 瀛楄妭/瀛楋紝2000 瀛楀氨 18KB锛�
+ // 瓒呰繃 Tomcat 榛樿 8KB 鐨勮姹傝涓婇檺浼氬緱鍒� "Request header is too large"銆�
+ // 闃堝�煎彇 1000 瀛楋紙绾� 9KB 缂栫爜鍚庝粛鍋忛珮锛夛紝瓒呰繃灏辫蛋鏆傚瓨銆�
+ let imageTextId = null
+ let inlineImageText = imageText
+ if (imageText && imageText.length > 1000) {
+ try {
+ const stored = await storeAttachmentText(imageText)
+ imageTextId = stored?.id || null
+ if (imageTextId) {
+ inlineImageText = null
+ }
+ } catch (error) {
+ // 鏆傚瓨澶辫触灏遍��鍥炲唴鑱斾紶閫掞紱鍐呭涓嶉暱鏃朵粛鍙敤锛�
+ // 杩囬暱鏃跺悗绔細缁欏嚭鏄庣‘鎻愮ず鑰屼笉鏄潤榛樺け璐�
+ message.warning(`鍥剧墖鏂囧瓧鏆傚瓨澶辫触锛屽皢灏濊瘯鐩存帴鍙戦�侊細${error.message || ''}`)
+ }
+ }
+
+ try {
+ await chatStore.sendMessage({
+ chatId: props.chatId,
+ content,
+ useRag: useRag.value && hasRag.value,
+ imageText: inlineImageText,
+ imageTextId,
+ imageFileIds
+ })
+ } catch (error) {
+ message.error(error.message || '鍙戦�佸け璐�')
+ // 鍙戦�佸け璐ユ妸鍐呭杩樺洖杈撳叆妗嗭紝閬垮厤鐢ㄦ埛鐧芥墦瀛椼��
+ // 鍥剧墖涓嶈繕鍘燂細鏂囦欢宸插湪鏈嶅姟绔惤鐩橈紝閲嶆柊璇嗗埆涓�閬嶄唬浠锋洿楂橈紝
+ // 鐢ㄦ埛閲嶆柊閫夊浘鍗冲彲锛堟秷鎭爲閲屼篃娌℃湁浜х敓鍨冨溇娑堟伅锛夈��
+ draft.value = content
+ } finally {
+ inputRef.value?.focus?.()
+ }
+}
+
+async function handleRegenerate(msg) {
+ try {
+ await chatStore.regenerate({
+ chatId: props.chatId,
+ userMessageId: msg.id,
+ useRag: useRag.value && hasRag.value
+ })
+ } catch (error) {
+ message.error(error.message || '閲嶆柊鐢熸垚澶辫触')
+ }
+}
+
+async function handleEdit(msg, content) {
+ try {
+ await chatStore.editMessage(props.chatId, msg.id, content)
+ message.success('宸蹭繚瀛�')
+ } catch (error) {
+ message.error(error.message || '淇濆瓨澶辫触')
+ }
+}
+
+function handleDelete(msg) {
+ dialog.warning({
+ title: '鍒犻櫎娑堟伅',
+ content: '璇ユ秷鎭強鍏朵箣鍚庣殑鎵�鏈夊璇濋兘浼氳鍒犻櫎锛岀‘瀹氱户缁悧锛�',
+ positiveText: '鍒犻櫎',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await chatStore.removeMessage(props.chatId, msg.id)
+ message.success('宸插垹闄�')
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎澶辫触')
+ }
+ }
+ })
+}
+
+// ---------------- 鍙傛暟 ----------------
+
+async function saveMeta() {
+ savingMeta.value = true
+ try {
+ await chatStore.updateChatMeta(props.chatId, {
+ modelName: metaForm.value.modelName || null,
+ temperature: metaForm.value.temperature,
+ topP: metaForm.value.topP,
+ numCtx: metaForm.value.numCtx || null,
+ systemPrompt: metaForm.value.systemPrompt || null
+ })
+ message.success('鍙傛暟宸蹭繚瀛�')
+ showSettings.value = false
+ } catch (error) {
+ message.error(error.message || '淇濆瓨澶辫触')
+ } finally {
+ savingMeta.value = false
+ }
+}
+
+// ---------------- 鐭ヨ瘑搴� ----------------
+
+async function handleUploaded(uploaded) {
+ files.value = [...uploaded, ...files.value]
+ // 涓婁紶鏃惰嫢閫変簡鍒嗙被锛屽垎绫荤殑鏂囨。鏁板彉浜嗭紝杩炲悓鏂囦欢鍒楄〃涓�璧峰埛鏂�
+ await refreshRagState(props.chatId)
+}
+
+/**
+ * 鍦ㄤ笂浼犲尯鐜板満鏂板缓浜嗗垎绫汇��
+ *
+ * 蹇呴』鍒锋柊鍒嗙被鍒楄〃 鈥斺�� 鍚﹀垯鐢ㄦ埛鍒氬缓鐨勫垎绫讳笉浼氬嚭鐜板湪涓婃柟鐨�
+ * 銆屽垎绫荤粦瀹氥�嶅尯閲岋紝鐪嬭捣鏉ュ儚娌″缓鎴愬姛銆�
+ */
+async function handleCategoryCreated() {
+ await refreshRagState(props.chatId)
+}
+
+async function handleIngest(file) {
+ ingestingId.value = file.id
+ try {
+ const updated = await ingestFile(file.id)
+ const index = files.value.findIndex((item) => item.id === file.id)
+ if (index !== -1) {
+ files.value[index] = updated
+ }
+ message.success(`鍚戦噺鍖栧畬鎴愶紝鍏� ${updated.chunkCount} 涓墖娈礰)
+ } catch (error) {
+ message.error(error.message || '鍚戦噺鍖栧け璐�')
+ // 閲嶆柊鎷夊彇浠ユ樉绀哄悗绔殑澶辫触鐘舵��
+ try {
+ files.value = await listFiles(null)
+ } catch {
+ // 蹇界暐
+ }
+ } finally {
+ ingestingId.value = null
+ }
+}
+
+async function toggleBinding(collectionName) {
+ const next = boundCollections.value.includes(collectionName)
+ ? boundCollections.value.filter((name) => name !== collectionName)
+ : [...boundCollections.value, collectionName]
+
+ try {
+ // 鍚庣鏄叏閲忚鐩栬涔夛紝鍥犳鎻愪氦瀹屾暣鍒楄〃銆�
+ // 杩斿洖鐨勬槸**瀹為檯缁戝畾鎴愬姛**鐨勫垪琛� 鈥斺�� 宸插け鏁堢殑闆嗗悎鍚庣浼氬拷鐣ワ紝
+ // 鎵�浠ヨ繖閲屽繀椤荤敤杩斿洖鍊艰鐩栨湰鍦扮姸鎬侊紝鍚﹀垯鏈湴浼氫竴鐩存畫鐣�
+ // 閭d釜宸插け鏁堢殑闆嗗悎鍚嶏紝瀵艰嚧姣忔缁戝畾閮介噸澶嶆彁浜ゅ畠銆�
+ const applied = (await bindCollections(props.chatId, next)) || []
+ boundCollections.value = applied
+ if (hasRag.value) {
+ useRag.value = true
+ }
+
+ // 鍛婄煡琚墧闄ょ殑椤癸紝閬垮厤鐢ㄦ埛瑙夊緱銆岀偣浜嗘病鍙嶅簲銆�
+ const dropped = next.filter((name) => !applied.includes(name))
+ if (dropped.length > 0) {
+ message.warning(
+ `${dropped.length} 涓煡璇嗗簱宸插け鏁堬紙鏂囨。鍙兘宸茶鍒犻櫎鎴栬鍙栨秷鍏ㄥ眬锛夛紝宸茶嚜鍔ㄧЩ闄わ細` +
+ dropped.join('銆�')
+ )
+ // 鎷変竴娆℃枃浠跺垪琛紝璁╁け鏁堟枃妗d粠鐣岄潰涓婃秷澶�
+ await refreshRagState(props.chatId)
+ } else {
+ message.success(applied.length ? '缁戝畾宸叉洿鏂�' : '宸茶В闄ゅ叏閮ㄧ粦瀹�')
+ }
+ } catch (error) {
+ message.error(error.message || '缁戝畾澶辫触')
+ }
+}
+
+function handleDeleteFile(file) {
+ dialog.warning({
+ title: '鍒犻櫎鏂囨。',
+ content: `纭畾鍒犻櫎銆�${file.filename}銆嶅悧锛熺鐩樻枃浠朵笌宸插叆搴撶殑鍚戦噺閮戒細涓�骞舵竻鐞嗐�俙,
+ positiveText: '鍒犻櫎',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await deleteFile(file.id)
+ files.value = files.value.filter((item) => item.id !== file.id)
+ if (file.collectionName) {
+ boundCollections.value = boundCollections.value.filter(
+ (name) => name !== file.collectionName
+ )
+ }
+ message.success('宸插垹闄�')
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎澶辫触')
+ }
+ }
+ })
+}
+
+function formatSize(bytes) {
+ if (!bytes && bytes !== 0) return ''
+ if (bytes < 1024) return `${bytes} B`
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`
+}
+
+// ---------------- 鐢熷懡鍛ㄦ湡 ----------------
+
+onMounted(() => {
+ document.addEventListener('paste', handleDocumentPaste)
+})
+
+onBeforeUnmount(() => {
+ document.removeEventListener('paste', handleDocumentPaste)
+ // 绂诲紑椤甸潰鏃堕噴鏀炬湭鍙戦�佸浘鐗囩殑 ObjectURL锛岄伩鍏嶆硠婕�
+ clearPendingImages()
+})
+
+function scrollToBottom() {
+ nextTick(() => {
+ const el = scrollRef.value
+ if (el) {
+ el.scrollTop = el.scrollHeight
+ }
+ })
+}
+
+defineExpose({ refreshRagState })
+</script>
+
+<style scoped>
+.chat-view {
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+ min-width: 0;
+ height: 100vh;
+ background: var(--bg-page);
+}
+
+.chat-header {
+ height: 54px;
+ border-bottom: 1px solid var(--border-color);
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0 16px;
+ flex-shrink: 0;
+}
+
+.chat-header-left,
+.chat-header-right {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+}
+
+.header-btn {
+ font-size: 15px;
+}
+
+.chat-title-area {
+ margin-left: 8px;
+ min-width: 0;
+}
+
+.chat-title {
+ font-size: 14px;
+ font-weight: 600;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ max-width: 380px;
+}
+
+.chat-subtitle {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 1px;
+}
+
+.rag-badge {
+ margin-left: 8px;
+ color: #0f766e;
+}
+
+.message-list {
+ flex: 1;
+ overflow-y: auto;
+ padding: 8px 24px 24px;
+ scroll-behavior: smooth;
+}
+
+.welcome {
+ text-align: center;
+ padding-top: 16vh;
+}
+
+.welcome-logo {
+ width: 56px;
+ height: 56px;
+ margin: 0 auto 18px;
+ border-radius: 15px;
+ background: #374151;
+ color: #fff;
+ font-weight: 700;
+ font-size: 20px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.welcome-title {
+ margin: 0 0 8px;
+ font-size: 21px;
+ font-weight: 600;
+}
+
+.welcome-sub {
+ margin: 0;
+ font-size: 13.5px;
+ color: var(--text-secondary);
+ line-height: 1.9;
+}
+
+.stream-error {
+ margin: 0 24px 8px;
+ padding: 9px 12px;
+ background: #fef2f2;
+ border: 1px solid #fecaca;
+ border-radius: 8px;
+ font-size: 13px;
+ color: #b91c1c;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+ max-width: 780px;
+ align-self: center;
+ width: calc(100% - 48px);
+ box-sizing: border-box;
+}
+
+.error-close {
+ background: none;
+ border: none;
+ font-size: 17px;
+ line-height: 1;
+ cursor: pointer;
+ color: #b91c1c;
+ padding: 0 2px;
+}
+
+.composer {
+ padding: 8px 24px 16px;
+ flex-shrink: 0;
+}
+
+.composer-inner {
+ max-width: 780px;
+ margin: 0 auto;
+ border: 1px solid var(--border-color);
+ border-radius: 12px;
+ padding: 10px 12px 8px;
+ box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
+ transition: border-color 0.15s ease;
+}
+
+.composer-inner:focus-within {
+ border-color: #9ca3af;
+}
+
+.composer-inner :deep(.n-input) {
+ --n-border: none !important;
+ --n-border-hover: none !important;
+ --n-border-focus: none !important;
+ --n-box-shadow-focus: none !important;
+}
+
+.hidden-image-input {
+ display: none;
+}
+
+.pending-images {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ margin-bottom: 8px;
+}
+
+.pending-image {
+ position: relative;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 6px 26px 6px 6px;
+ border: 1px solid var(--border-color);
+ border-radius: 8px;
+ background: #fafafa;
+ max-width: 260px;
+}
+
+.pending-thumb {
+ width: 40px;
+ height: 40px;
+ object-fit: cover;
+ border-radius: 6px;
+ flex-shrink: 0;
+}
+
+.pending-info {
+ min-width: 0;
+}
+
+.pending-name {
+ font-size: 12px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.pending-status {
+ font-size: 11px;
+ color: var(--text-muted);
+ margin-top: 2px;
+}
+
+.pending-status.done {
+ color: #0f766e;
+}
+
+.pending-status.failed {
+ color: #dc2626;
+}
+
+.pending-remove {
+ position: absolute;
+ top: 2px;
+ right: 4px;
+ background: none;
+ border: none;
+ cursor: pointer;
+ font-size: 15px;
+ line-height: 1;
+ color: var(--text-muted);
+ padding: 0 2px;
+}
+
+.pending-remove:hover {
+ color: #dc2626;
+}
+
+.composer-actions {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin-top: 8px;
+}
+
+.rag-toggle {
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ cursor: pointer;
+}
+
+.rag-toggle-label {
+ font-size: 12.5px;
+ color: var(--text-secondary);
+}
+
+.rag-toggle-label.disabled {
+ color: var(--text-muted);
+}
+
+.composer-buttons {
+ display: flex;
+ gap: 8px;
+}
+
+.composer-hint {
+ text-align: center;
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 8px;
+}
+
+/* ---------------- 鎶藉眽鍐呴儴 ---------------- */
+.rag-alert {
+ margin-bottom: 16px;
+ font-size: 12.5px;
+ line-height: 1.8;
+}
+
+.rag-section-title {
+ font-size: 13px;
+ font-weight: 600;
+ margin: 20px 0 10px;
+}
+
+.rag-section-title:first-of-type {
+ margin-top: 0;
+}
+
+.section-refresh {
+ float: right;
+ font-size: 11.5px;
+ color: var(--text-secondary);
+ margin-top: 1px;
+}
+
+.section-hint {
+ font-weight: 400;
+ color: var(--text-muted);
+ font-size: 11.5px;
+ margin-left: 6px;
+}
+
+.category-row {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 10px;
+ padding: 10px 12px;
+ border: 1px solid var(--border-color);
+ border-radius: 8px;
+ margin-bottom: 8px;
+ background: #fcfcfd;
+}
+
+.category-row-main {
+ min-width: 0;
+ flex: 1;
+}
+
+.category-name {
+ font-size: 13px;
+ font-weight: 500;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.category-meta {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 3px;
+}
+
+.file-category {
+ color: #0f766e;
+}
+
+.file-row {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 10px;
+ padding: 10px 0;
+ border-bottom: 1px solid #f3f4f6;
+}
+
+.file-row-main {
+ min-width: 0;
+ flex: 1;
+}
+
+.file-name {
+ font-size: 13px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+/* 鍏ㄥ眬鐭ヨ瘑搴撴爣璁帮細鎻愮ず杩欎釜鏂囨。鏄叏鍛樺叡鐢ㄧ殑鍏叡鐭ヨ瘑搴� */
+.global-badge {
+ display: inline-block;
+ margin-left: 6px;
+ padding: 0 5px;
+ font-size: 11px;
+ line-height: 16px;
+ border-radius: 4px;
+ color: #0f766e;
+ background: #ecfdf5;
+ vertical-align: middle;
+}
+
+.file-meta {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 3px;
+}
+
+.file-status.ok {
+ color: #0f766e;
+}
+
+.file-status.fail {
+ color: #dc2626;
+}
+
+.file-status.pending {
+ color: #b45309;
+}
+
+.file-row-actions {
+ display: flex;
+ gap: 4px;
+ flex-shrink: 0;
+}
+
+.rag-footer {
+ font-size: 12.5px;
+}
+</style>
diff --git a/src/components/FileUpload.vue b/src/components/FileUpload.vue
new file mode 100644
index 0000000..2277baa
--- /dev/null
+++ b/src/components/FileUpload.vue
@@ -0,0 +1,289 @@
+<template>
+ <div class="file-upload">
+ <div
+ class="drop-zone"
+ :class="{ dragging: isDragging, uploading }"
+ @dragover.prevent="isDragging = true"
+ @dragleave.prevent="isDragging = false"
+ @drop.prevent="handleDrop"
+ @click="pickFile"
+ >
+ <input
+ ref="fileInputRef"
+ type="file"
+ class="hidden-input"
+ multiple
+ :accept="acceptAttr"
+ @change="handleSelect"
+ />
+ <div class="drop-icon">鈫�</div>
+ <div class="drop-title">
+ {{ uploading ? statusText : '鎷栨嫿鏂囦欢鍒版澶勶紝鎴栫偣鍑婚�夋嫨' }}
+ </div>
+ <div class="drop-hint">
+ 鏀寔 {{ allowedExtensions.join(' / ') }}锛屽崟涓枃浠朵笉瓒呰繃 {{ maxSizeMb }}MB
+ </div>
+ <n-progress
+ v-if="uploading"
+ type="line"
+ :percentage="progress"
+ :show-indicator="false"
+ class="drop-progress"
+ />
+ </div>
+
+ <!-- 涓婁紶鍓嶉�夊ソ鍒嗙被锛屼笂浼犲悗鑷姩褰掔被锛岀渷鍘讳紶瀹屽啀涓�涓釜鎸囧畾 -->
+ <div v-if="showCategory" class="upload-category">
+ <CategoryPicker
+ v-model:value="categoryId"
+ :allow-global="allowGlobalCategory"
+ :disabled="uploading"
+ placeholder="閫夋嫨鍒嗙被锛堝彲涓嶉�夛級"
+ @created="$emit('category-created', $event)"
+ />
+ </div>
+
+ <!--
+ 鑷姩鍚戦噺鍖栧紑鍏筹細榛樿寮�鍚��
+ 鍏虫帀瀹冨彧鏈夊湪銆屾壒閲忎笂浼犲嚑鐧句釜鏂囦欢銆佹兂鑷繁鎺у埗鍏ュ簱鏃舵満銆嶆椂鎵嶆湁鎰忎箟锛�
+ 鎵�浠ユ斁鍦ㄦ瑕佷綅缃紝涓嶆姠瑙嗚鐒︾偣銆�
+ -->
+ <label class="auto-ingest">
+ <n-switch v-model:value="autoIngest" size="small" :disabled="uploading" />
+ <span class="auto-ingest-label">
+ 涓婁紶鍚庣珛鍗冲悜閲忓寲
+ <span class="auto-ingest-hint">锛堝叧闂悗闇�鎵嬪姩鐐广�屽悜閲忓寲銆嶆墠鑳借妫�绱㈠埌锛�</span>
+ </span>
+ </label>
+
+ <div v-if="error" class="upload-error">{{ error }}</div>
+ </div>
+</template>
+
+<script setup>
+import { computed, ref } from 'vue'
+import { NProgress, NSwitch, useMessage } from 'naive-ui'
+import { uploadFile } from '@/api/fileApi'
+import CategoryPicker from './CategoryPicker.vue'
+
+const props = defineProps({
+ /** 缁戝畾鐨勪細璇� id锛涗负绌鸿〃绀轰笂浼犱负鍏叡鐭ヨ瘑搴撴枃浠� */
+ chatId: { type: Number, default: null },
+ /** 鍗曟枃浠跺ぇ灏忎笂闄愶紙MB锛� */
+ maxSizeMb: { type: Number, default: 50 },
+ /** 鏄惁鏄剧ず鍒嗙被閫夋嫨鍣� */
+ showCategory: { type: Boolean, default: true },
+ /** 鏄惁鍏佽鍒涘缓鍏ㄥ眬鍒嗙被锛堜粎绠$悊鍛橀〉闈紶 true锛� */
+ allowGlobalCategory: { type: Boolean, default: false }
+})
+
+const emit = defineEmits(['uploaded', 'category-created'])
+
+const message = useMessage()
+const fileInputRef = ref(null)
+const isDragging = ref(false)
+const uploading = ref(false)
+const progress = ref(0)
+const error = ref('')
+// 榛樿寮�鍚細鏈叆搴撶殑鏂囦欢瀵规绱㈡棤鏁堬紝銆屼笂浼犲畬鍗存悳涓嶅埌銆嶆槸鏈�瀹规槗璁╀汉鍥版儜鐨勫満鏅�
+const autoIngest = ref(true)
+/** 閫変腑鐨勫垎绫伙紱null 琛ㄧず涓嶅綊绫� */
+const categoryId = ref(null)
+/** 褰撳墠闃舵鏂囨锛氫笂浼犲瓧鑺� vs 鍚戦噺鍖栵紙鍚庤�呰�楁椂閫氬父杩滃ぇ浜庡墠鑰咃級 */
+const statusText = ref('')
+
+/**
+ * 涓婁紶闃舵鐨勮繘搴︽槧灏勩��
+ *
+ * 涓婁紶瀛楄妭鍙崰鏁翠釜娴佺▼鐨勪竴灏忛儴鍒嗭紝鍚戦噺鍖栵紙瑙f瀽 + embedding + 鍐欏悜閲忓簱锛�
+ * 鎵嶆槸涓昏鑰楁椂銆傝嫢鎶婃�昏繘搴︾洿鎺ユ寜涓婁紶鐧惧垎姣旀樉绀猴紝浼氬崱鍦� 100% 涓嶅姩锛�
+ * 鐢ㄦ埛浠ヤ负鍗℃浜嗐�傚洜姝ゆ妸涓婁紶鏄犲皠鍒� 0-40%锛屽墿涓嬬殑鐣欑粰鍚戦噺鍖栭樁娈点��
+ */
+const uploadPhasePercent = (rawPercent) => Math.round(rawPercent * 0.4)
+
+// 涓庡悗绔� webui.storage.allowed-extensions 淇濇寔涓�鑷淬��
+// 鍓嶇闄愬埗鍙槸浣撻獙浼樺寲锛岀湡姝g殑瀹夊叏杈圭晫鍦ㄥ悗绔��
+const allowedExtensions = [
+ 'txt', 'md', 'markdown', 'pdf', 'docx', 'csv', 'json', 'log', 'html',
+ // 鍥剧墖浼氳蛋 OCR 鎻愬彇鏂囧瓧鍚庡叆搴�
+ 'png', 'jpg', 'jpeg', 'webp', 'bmp', 'gif', 'tif', 'tiff'
+]
+
+const acceptAttr = computed(() =>
+ allowedExtensions.map((ext) => `.${ext}`).join(',')
+)
+
+function pickFile() {
+ if (uploading.value) return
+ fileInputRef.value?.click()
+}
+
+function handleSelect(event) {
+ const files = Array.from(event.target.files || [])
+ // 娓呯┖ value锛屽惁鍒欓�夋嫨鍚屼竴涓枃浠朵笉浼氬啀娆¤Е鍙� change 浜嬩欢
+ event.target.value = ''
+ uploadFiles(files)
+}
+
+function handleDrop(event) {
+ isDragging.value = false
+ if (uploading.value) return
+ uploadFiles(Array.from(event.dataTransfer?.files || []))
+}
+
+async function uploadFiles(files) {
+ if (files.length === 0) return
+
+ error.value = ''
+ uploading.value = true
+ progress.value = 0
+
+ const succeeded = []
+
+ try {
+ for (let index = 0; index < files.length; index += 1) {
+ const file = files[index]
+
+ // 瀹㈡埛绔妫�锛氱粰鍑哄嵆鏃跺弽棣堬紝涓嶅繀绛変竴涓潵鍥�
+ const extension = file.name.split('.').pop()?.toLowerCase() || ''
+ if (!allowedExtensions.includes(extension)) {
+ message.error(`${file.name}锛氫笉鏀寔鐨勬枃浠剁被鍨� .${extension}`)
+ continue
+ }
+ if (file.size > props.maxSizeMb * 1024 * 1024) {
+ message.error(`${file.name}锛氳秴杩� ${props.maxSizeMb}MB 闄愬埗`)
+ continue
+ }
+
+ try {
+ const base = index / files.length
+ const slice = 1 / files.length
+
+ statusText.value = `涓婁紶涓� ${file.name}`
+ progress.value = Math.round(base * 100)
+
+ const result = await uploadFile(
+ file,
+ props.chatId,
+ (percent) => {
+ // 涓婁紶鍙崰璇ユ枃浠惰繘搴︾殑鍓� 40%锛屽墿浣欑暀缁欏悜閲忓寲
+ progress.value = Math.round((base + (uploadPhasePercent(percent) / 100) * slice) * 100)
+ },
+ autoIngest.value,
+ categoryId.value
+ )
+
+ // 涓婁紶宸茶繑鍥烇紝鑻ュ紑鍚簡鑷姩鍚戦噺鍖栵紝鍚庣姝ゆ椂宸茬粡鍋氬畬鍏ュ簱
+ progress.value = Math.round((base + slice) * 100)
+
+ if (autoIngest.value && result && result.ingested === false && result.ingestMessage) {
+ // 鏂囦欢瀛樹笅鏉ヤ簡锛屼絾鍚戦噺鍖栧け璐� 鈥斺�� 鏄庣‘鍛婄煡锛屼笉闈欓粯鍚炴帀
+ message.warning(`${file.name} 宸蹭笂浼狅紝浣�${result.ingestMessage}`)
+ } else if (autoIngest.value && result && result.chunkCount) {
+ message.success(`${file.name} 宸插叆搴� ${result.chunkCount} 涓墖娈礰)
+ }
+ succeeded.push(result)
+ } catch (uploadError) {
+ message.error(`${file.name}锛�${uploadError.message || '涓婁紶澶辫触'}`)
+ }
+ }
+
+ if (succeeded.length > 0) {
+ const ingested = succeeded.filter((f) => f && f.ingested).length
+ if (autoIngest.value) {
+ message.success(`鎴愬姛涓婁紶 ${succeeded.length} 涓枃浠讹紝鍏朵腑 ${ingested} 涓凡鍏ュ簱鍙绱)
+ } else {
+ // 鍏虫帀鑷姩鍚戦噺鍖栨椂蹇呴』璇存竻妤氬悗鏋滐紝鍚﹀垯鐢ㄦ埛浼氫互涓哄凡缁忚兘鐢ㄤ簡
+ message.info(`鎴愬姛涓婁紶 ${succeeded.length} 涓枃浠讹紝灏氭湭鍚戦噺鍖栵紝闇�鐐广�屽悜閲忓寲銆嶅悗鎵嶈兘琚绱㈠埌`)
+ }
+ emit('uploaded', succeeded)
+ }
+ } finally {
+ uploading.value = false
+ progress.value = 0
+ statusText.value = ''
+ }
+}
+</script>
+
+<style scoped>
+.hidden-input {
+ display: none;
+}
+
+.drop-zone {
+ border: 1.5px dashed #d1d5db;
+ border-radius: 10px;
+ padding: 22px 16px;
+ text-align: center;
+ cursor: pointer;
+ background: #fafafa;
+ transition: border-color 0.15s ease, background 0.15s ease;
+}
+
+.drop-zone:hover {
+ border-color: #9ca3af;
+ background: #f5f5f5;
+}
+
+.drop-zone.dragging {
+ border-color: #4b5563;
+ background: #eef2f7;
+}
+
+.drop-zone.uploading {
+ cursor: progress;
+}
+
+.drop-icon {
+ font-size: 20px;
+ color: var(--text-secondary);
+ margin-bottom: 8px;
+}
+
+.drop-title {
+ font-size: 13.5px;
+ color: var(--text-primary);
+ font-weight: 500;
+}
+
+.drop-hint {
+ font-size: 12px;
+ color: var(--text-muted);
+ margin-top: 6px;
+ line-height: 1.6;
+}
+
+.drop-progress {
+ margin-top: 12px;
+}
+
+.upload-category {
+ margin-top: 10px;
+}
+
+.auto-ingest {
+ display: flex;
+ align-items: flex-start;
+ gap: 8px;
+ margin-top: 10px;
+ cursor: pointer;
+ user-select: none;
+}
+
+.auto-ingest-label {
+ font-size: 12.5px;
+ color: var(--text-secondary);
+ line-height: 1.5;
+}
+
+.auto-ingest-hint {
+ color: var(--text-muted);
+}
+
+.upload-error {
+ margin-top: 8px;
+ font-size: 12.5px;
+ color: #dc2626;
+}
+</style>
diff --git a/src/components/MessageItem.vue b/src/components/MessageItem.vue
new file mode 100644
index 0000000..50d41d5
--- /dev/null
+++ b/src/components/MessageItem.vue
@@ -0,0 +1,716 @@
+<template>
+ <div class="message-item" :class="[`role-${message.role}`, { streaming: isStreaming }]">
+ <!-- 澶村儚 -->
+ <div class="message-avatar" :class="message.role">
+ {{ message.role === 'user' ? userInitial : 'AI' }}
+ </div>
+
+ <div class="message-body">
+ <div class="message-header">
+ <span class="message-role">
+ {{ message.role === 'user' ? '浣�' : '鍔╂墜' }}
+ <span v-if="message.model" class="message-model">{{ message.model }}</span>
+ </span>
+
+ <span class="message-actions">
+ <!-- 鍒嗘敮鍒囨崲鍣細鍚屼竴鐖惰妭鐐逛笅鏈夊鏉″洖澶嶆椂鎵嶅嚭鐜� -->
+ <span v-if="branchInfo.total > 1" class="branch-switch">
+ <button
+ class="branch-btn"
+ :disabled="branchInfo.index <= 1"
+ title="涓婁竴涓垎鏀�"
+ @click="$emit('switch-branch', -1)"
+ >
+ 鈥�
+ </button>
+ <span class="branch-label">{{ branchInfo.index }}/{{ branchInfo.total }}</span>
+ <button
+ class="branch-btn"
+ :disabled="branchInfo.index >= branchInfo.total"
+ title="涓嬩竴涓垎鏀�"
+ @click="$emit('switch-branch', 1)"
+ >
+ 鈥�
+ </button>
+ </span>
+
+ <button
+ v-if="message.role === 'user' && !isStreaming"
+ class="action-btn"
+ title="缂栬緫骞剁敱姝や骇鐢熸柊鍒嗘敮"
+ @click="startEdit"
+ >
+ 缂栬緫
+ </button>
+ <button
+ v-if="message.role === 'user' && !isStreaming"
+ class="action-btn"
+ title="閲嶆柊鐢熸垚鍥炲"
+ @click="$emit('regenerate')"
+ >
+ 閲嶆柊鐢熸垚
+ </button>
+ <button
+ v-if="!isStreaming"
+ class="action-btn"
+ title="澶嶅埗鍐呭"
+ @click="copyContent"
+ >
+ 澶嶅埗
+ </button>
+ <button
+ v-if="!isStreaming"
+ class="action-btn danger"
+ title="鍒犻櫎璇ユ秷鎭強鍏跺悗缁璇�"
+ @click="$emit('delete')"
+ >
+ 鍒犻櫎
+ </button>
+ </span>
+ </div>
+
+ <!-- 缂栬緫鎬� -->
+ <div v-if="editing" class="edit-area">
+ <n-input
+ v-model:value="editContent"
+ type="textarea"
+ :autosize="{ minRows: 2, maxRows: 12 }"
+ placeholder="淇敼娑堟伅鍐呭"
+ />
+ <div class="edit-actions">
+ <n-button size="small" @click="cancelEdit">鍙栨秷</n-button>
+ <n-button size="small" type="primary" @click="commitEdit">淇濆瓨</n-button>
+ </div>
+ </div>
+
+ <!-- 娓叉煋鎬� -->
+ <div v-else>
+ <!-- 闅忔秷鎭笂浼犵殑鍥剧墖锛氭樉绀哄師鍥撅紝骞跺彲灞曞紑 OCR 鏂囧瓧 -->
+ <div v-if="images.length" class="message-images">
+ <div v-for="img in images" :key="img.id" class="message-image" @click="openPreview(img.id)">
+ <!--
+ 蹇呴』鐢� AuthenticatedImage 鑰屼笉鏄8 <img>锛�
+ 鏂囦欢鍐呭鎺ュ彛闇�瑕� Authorization 澶达紝鑰� <img> 涓嶄細甯﹁嚜瀹氫箟澶达紝
+ 鐩存帴鍐� src 浼氭嬁鍒� 401 骞舵樉绀烘垚銆屽浘鐗囨崯鍧忋�嶃��
+ -->
+ <AuthenticatedImage :file-id="img.id" alt="涓婁紶鐨勫浘鐗�" />
+ </div>
+ </div>
+
+ <div
+ class="message-content"
+ :class="{ 'typing-cursor': isStreaming }"
+ v-html="renderedContent"
+ ></div>
+
+ <!-- 鍥剧墖鏈夎瘑鍒枃瀛楁椂缁欎釜鎶樺彔鍏ュ彛锛氱敤鎴峰彲鑳芥兂鏍稿妯″瀷鐪嬪埌鐨勫唴瀹� -->
+ <div v-if="imageText" class="ocr-text">
+ <span class="ocr-toggle" @click="showOcrText = !showOcrText">
+ {{ showOcrText ? '鏀惰捣' : '鏌ョ湅' }}鍥剧墖璇嗗埆鏂囧瓧锛坽{ imageText.length }} 瀛楋級
+ </span>
+ <pre v-if="showOcrText" class="ocr-content">{{ imageText }}</pre>
+ </div>
+ </div>
+
+ <!-- 鐐瑰嚮缂╃暐鍥炬斁澶э細澶嶇敤鍚屼竴涓壌鏉冨浘鐗囩粍浠讹紝閬垮厤鍐嶅啓涓�濂楀彇鍥鹃�昏緫 -->
+ <n-modal
+ v-if="previewImageId != null"
+ :show="previewImageId != null"
+ preset="card"
+ class="image-preview-modal"
+ :bordered="false"
+ @update:show="(v) => { if (!v) previewImageId = null }"
+ >
+ <AuthenticatedImage
+ :file-id="previewImageId"
+ alt="鍥剧墖棰勮"
+ class="preview-large"
+ />
+ </n-modal>
+
+ <!-- 鍋滄 / 澶辫触鏍囪 -->
+ <div v-if="message.stopped" class="message-note">宸叉墜鍔ㄥ仠姝㈢敓鎴�</div>
+ <div v-if="message.failed" class="message-note error">鐢熸垚澶辫触</div>
+
+ <!-- RAG 寮曠敤鏉ユ簮锛氱紪鍙蜂笌姝f枃閲岀殑 [1] 涓�涓�瀵瑰簲 -->
+ <div v-if="sources.length" class="rag-sources">
+ <div class="rag-sources-title">寮曠敤鏉ユ簮锛坽{ sources.length }}锛�</div>
+ <div
+ v-for="(source, index) in sources"
+ :key="index"
+ class="rag-source"
+ :title="source.snippet || ''"
+ >
+ <span class="rag-source-index">[{{ index + 1 }}]</span>
+ <span class="rag-source-body">
+ <span class="rag-source-name">{{ source.filename || '鏈煡鏂囨。' }}</span>
+ <!-- 绔犺妭锛氭妸寮曠敤浠庛�屾枃浠跺悕銆嶇粏鍖栧埌銆屾枃妗g殑鍝竴鑺傘�� -->
+ <span v-if="source.section" class="rag-source-section">
+ {{ source.section }}
+ </span>
+ </span>
+ <span v-if="source.score != null" class="rag-source-score">
+ {{ scoreLabel(source.score) }}
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup>
+import { computed, ref } from 'vue'
+import { NButton, NInput, NModal, useMessage } from 'naive-ui'
+import AuthenticatedImage from './AuthenticatedImage.vue'
+import { renderMarkdown } from '@/utils/markdown'
+
+const props = defineProps({
+ message: { type: Object, required: true },
+ /** 璇ユ秷鎭槸鍚︽鍦ㄦ祦寮忕敓鎴� */
+ isStreaming: { type: Boolean, default: false },
+ /** 褰撳墠鏄剧ず鐨勬槸绗嚑涓垎鏀紝鐢辩埗缁勪欢浠� store 璁$畻鍚庝紶鍏� */
+ branchInfo: {
+ type: Object,
+ default: () => ({ index: 0, total: 0 })
+ },
+ userInitial: { type: String, default: 'U' }
+})
+
+const emit = defineEmits(['switch-branch', 'edit', 'regenerate', 'delete'])
+
+/**
+ * 娉ㄦ剰杩欎釜鍛藉悕 鈥斺�� 韪╄繃涓�涓緢闅愯斀鐨勫潙锛�
+ *
+ * NaiveUI 鐨勬秷鎭彁绀� API 涔犳儻涓婂啓浣� `const message = useMessage()`锛�
+ * 浣嗘湰缁勪欢鍚屾椂鏈変竴涓悕涓� `message` 鐨� **prop**锛堣娓叉煋鐨勯偅鏉℃秷鎭級銆�
+ * 涓よ�呭悓鍚嶆椂锛宍<script setup>` 涓殑 setup 缁戝畾浼樺厛绾ч珮浜� props锛�
+ * 浜庢槸妯℃澘閲岀殑 `message.role` / `message.content` 鍏ㄩ儴瑙f瀽鍒�
+ * **toast 瀵硅薄**涓� 鈥斺�� 缁撴灉鏄瘡鏉℃秷鎭兘琚覆鏌撴垚
+ * `role-undefined` + 銆岋紙绌烘秷鎭級銆嶏紝鑰� props 鏄庢槑鏄ソ鐨勩��
+ *
+ * 杩欑被 bug 涓嶆姤閿欍�佷笉鎶ヨ鍛婏紝鍙槸鍐呭鍑┖娑堝け锛岄潪甯搁毦鏌ャ��
+ * 鍥犳杩欓噷鎶� toast API 鏀瑰悕涓� `toast`锛岃 `message` 鍞竴鍦版寚鍚� prop銆�
+ * 鍏朵粬缁勪欢锛團ileUpload / Sidebar / ChatView锛夋病鏈夊悓鍚� prop锛�
+ * 鐢� message 涓嶄細鍑洪棶棰橈紝浣嗘柊缁勪欢寤鸿缁熶竴鐢� `toast`銆�
+ */
+const toast = useMessage()
+const editing = ref(false)
+const editContent = ref('')
+
+const sources = computed(() => props.message.sources || [])
+
+/** 闅忔秷鎭笂浼犵殑鍥剧墖 id 鍒楄〃 */
+const images = computed(() =>
+ (props.message.imageFileIds || []).map((id) => ({ id }))
+)
+
+/** 鍥剧墖鐨� OCR 鏂囧瓧锛堟湁鎵嶆樉绀烘姌鍙犲叆鍙o級 */
+const imageText = computed(() => props.message.imageText || '')
+
+const showOcrText = ref(false)
+/** 鐐瑰嚮缂╃暐鍥惧悗瑕佹斁澶х殑鍥剧墖 id锛坣ull 琛ㄧず涓嶆樉绀洪瑙堬級 */
+const previewImageId = ref(null)
+
+function openPreview(fileId) {
+ previewImageId.value = fileId
+}
+
+/**
+ * 鎶� Chroma 鐨� cosine 璺濈鎹㈢畻鎴愬彲璇荤殑鐩镐技搴︾櫨鍒嗘瘮銆�
+ *
+ * 璺濈 = 1 - 浣欏鸡鐩镐技搴︼紝鎵�浠ョ浉浼煎害 = (1 - 璺濈)銆�
+ * 鐩存帴灞曠ず銆岃窛绂� 0.248銆嶅鐢ㄦ埛娌℃湁鎰忎箟锛屽睍绀恒�岀浉浼煎害 75%銆嶆墠鐩磋銆�
+ */
+function scoreLabel(distance) {
+ const value = Number(distance)
+ if (!Number.isFinite(value)) return ''
+ const similarity = Math.max(0, Math.min(1, 1 - value))
+ return `鐩镐技搴� ${(similarity * 100).toFixed(0)}%`
+}
+
+/**
+ * 姝f枃娓叉煋锛歁arkdown 鈫� HTML銆�
+ *
+ * 鍏蜂綋鐨勫畨鍏ㄥ鐞嗭紙鍏堣浆涔夊啀瑙f瀽銆丏OMPurify 鍏滃簳銆佸紩鐢ㄧ紪鍙烽珮浜烦杩囦唬鐮佸潡锛�
+ * 閮藉皝瑁呭湪 utils/markdown.js 閲岋紝杩欓噷鍙礋璐f妸娴佸紡鐘舵�佷笌寮曠敤鏁伴噺浼犺繘鍘汇��
+ */
+const renderedContent = computed(() =>
+ renderMarkdown(props.message.content || '', {
+ streaming: props.isStreaming,
+ citationCount: sources.value.length
+ })
+)
+
+function startEdit() {
+ editing.value = true
+ editContent.value = props.message.content || ''
+}
+
+function cancelEdit() {
+ editing.value = false
+ editContent.value = ''
+}
+
+function commitEdit() {
+ const content = editContent.value.trim()
+ if (!content) {
+ toast.warning('鍐呭涓嶈兘涓虹┖')
+ return
+ }
+ editing.value = false
+ emit('edit', content)
+}
+
+async function copyContent() {
+ const text = props.message.content || ''
+ if (!text) return
+
+ try {
+ // navigator.clipboard 鍦ㄩ潪 HTTPS 鐜涓嬩笉鍙敤锛堝眬鍩熺綉 IP 璁块棶灏辨槸杩欑鎯呭喌锛夛紝
+ // 鍥犳淇濈暀 execCommand 鍥為��鏂规
+ if (navigator.clipboard && window.isSecureContext) {
+ await navigator.clipboard.writeText(text)
+ } else {
+ const textarea = document.createElement('textarea')
+ textarea.value = text
+ textarea.style.position = 'fixed'
+ textarea.style.opacity = '0'
+ document.body.appendChild(textarea)
+ textarea.select()
+ document.execCommand('copy')
+ document.body.removeChild(textarea)
+ }
+ toast.success('宸插鍒�')
+ } catch {
+ toast.error('澶嶅埗澶辫触锛岃鎵嬪姩閫夋嫨鏂囨湰')
+ }
+}
+</script>
+
+<style scoped>
+.message-item {
+ display: flex;
+ gap: 14px;
+ padding: 16px 0;
+ max-width: 780px;
+ margin: 0 auto;
+ width: 100%;
+}
+
+/*
+ * 鐢ㄦ埛娑堟伅闈犲彸銆丄I 娑堟伅闈犲乏锛岀鍚� ChatGPT / Open-WebUI 鐨勯槄璇讳範鎯��
+ *
+ * 鐢� row-reverse 鑰屼笉鏄� order锛歰rder 鍙敼鍙樿瑙夐『搴忥紝DOM 椤哄簭浠嶆槸
+ * 銆屽ご鍍� 鈫� 鍐呭銆嶏紝灞忓箷闃呰鍣ㄤ笌 Tab 鐒︾偣椤哄簭浼氬拰瑙嗚椤哄簭涓嶄竴鑷达紝
+ * 灞炰簬鏃犻殰纰嶇己闄枫�俽ow-reverse 缈昏浆鏁翠釜涓昏酱锛屽ご鍍忚嚜鐒惰惤鍒板彸渚э紝
+ * 涓� DOM 缁撴瀯瀹屽叏涓嶅彉銆�
+ */
+.message-item.role-user {
+ flex-direction: row-reverse;
+}
+
+/* 鐢ㄦ埛渚ф暣浣撻潬鍙� */
+.message-item.role-user .message-body {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
+}
+
+/* 鐢ㄦ埛娑堟伅鐨勬爣棰樿锛堣鑹插悕 + 鎿嶄綔鎸夐挳锛夊悓鏍烽潬鍙� */
+.message-item.role-user .message-header {
+ flex-direction: row-reverse;
+}
+
+.message-avatar {
+ width: 30px;
+ height: 30px;
+ border-radius: 7px;
+ flex-shrink: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 12px;
+ font-weight: 600;
+ color: #fff;
+}
+
+.message-avatar.user {
+ background: #4b5563;
+}
+
+.message-avatar.assistant {
+ background: #0f766e;
+}
+
+.message-body {
+ flex: 1;
+ min-width: 0;
+}
+
+/*
+ * 鐢ㄦ埛娑堟伅濂楁皵娉″簳鑹诧紝涓� AI 鐨勩�岀櫧搴曢�氭爮銆嶅舰鎴愯瑙夊尯鍒嗐��
+ * 鍚屾椂闄愬埗鏈�澶у搴� 鈥斺�� 闀挎秷鎭湪瀹藉睆涓婃í鍚戦摵婊′細璁╄绾挎潵鍥炴壂锛屽緢闅捐銆�
+ */
+.message-item.role-user .message-content {
+ background: var(--bubble-user);
+ border-radius: 12px;
+ padding: 9px 14px;
+ max-width: 85%;
+ width: fit-content;
+}
+
+/* 鐢ㄦ埛娑堟伅鐨勫紩鐢ㄦ潵婧愩�佺姸鎬佹彁绀哄悓鏍烽檺瀹介潬鍙� */
+.message-item.role-user .message-images {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ margin-bottom: 8px;
+}
+
+.message-image {
+ cursor: zoom-in;
+}
+
+/*
+ * 缂╃暐鍥惧昂瀵哥敱 AuthenticatedImage 鑷繁鐨� scoped 鏍峰紡鎺у埗 鈥斺��
+ * 杩欓噷鏄埗缁勪欢锛宻coped 灞炴�т綔鐢ㄤ笉鍒板瓙缁勪欢鍐呴儴鍏冪礌锛屽啓浜嗕篃涓嶇敓鏁堛��
+ * 鍙湪杩欓噷瀹氫箟銆岀偣寮�棰勮銆嶆椂鐨勮鐩栥��
+ */
+.message-image {
+ cursor: zoom-in;
+}
+
+.image-preview-modal {
+ width: auto;
+ max-width: 90vw;
+}
+
+/*
+ * 鏀惧ぇ棰勮锛氱敤 :deep 绌块�忓埌瀛愮粍浠跺唴閮ㄨ鐩栫缉鐣ュ浘涓婇檺銆�
+ * 鍚屾椂鏀惧紑瀹瑰櫒鐨� 160px 闄愬埗锛屽惁鍒欏浘鐗囦細琚鍣ㄥ崱浣忔斁涓嶅ぇ銆�
+ */
+.preview-large :deep(.authenticated-image) {
+ max-width: 86vw;
+ max-height: 82vh;
+}
+
+.preview-large :deep(.message-image-thumb) {
+ max-width: 86vw;
+ max-height: 82vh;
+ cursor: default;
+}
+
+.ocr-text {
+ margin-top: 8px;
+ font-size: 12px;
+}
+
+.ocr-toggle {
+ color: #0f766e;
+ cursor: pointer;
+}
+
+.ocr-toggle:hover {
+ text-decoration: underline;
+}
+
+.ocr-content {
+ margin: 6px 0 0;
+ padding: 8px 10px;
+ background: #f9fafb;
+ border: 1px solid var(--border-color);
+ border-radius: 6px;
+ white-space: pre-wrap;
+ word-break: break-word;
+ font-size: 12px;
+ color: var(--text-secondary);
+ max-height: 260px;
+ overflow-y: auto;
+}
+
+/* 鐢ㄦ埛娑堟伅閲岀殑鍥剧墖闈犲彸瀵归綈 */
+.message-item.role-user .message-images {
+ justify-content: flex-end;
+}
+
+.rag-sources {
+ max-width: 85%;
+}
+
+.message-item.role-user .message-note {
+ text-align: right;
+}
+
+/* 缂栬緫鎬佸湪鐢ㄦ埛渚т篃鐢ㄥ悓鏍风殑闄愬锛岄伩鍏嶇偣銆岀紪杈戙�嶆椂甯冨眬璺冲姩 */
+.message-item.role-user .edit-area {
+ width: 85%;
+}
+
+.message-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+ margin-bottom: 6px;
+ min-height: 20px;
+}
+
+.message-role {
+ font-size: 13px;
+ font-weight: 600;
+ color: var(--text-primary);
+}
+
+.message-model {
+ font-weight: 400;
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-left: 8px;
+ padding: 1px 6px;
+ background: #f3f4f6;
+ border-radius: 4px;
+}
+
+.message-actions {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ /* 榛樿闅愯棌鎿嶄綔鎸夐挳锛屽噺灏戣瑙夊櫔闊筹紱鎮仠鏁存潯娑堟伅鏃跺嚭鐜� */
+ opacity: 0;
+ transition: opacity 0.12s ease;
+}
+
+.message-item:hover .message-actions {
+ opacity: 1;
+}
+
+.action-btn {
+ background: none;
+ border: none;
+ padding: 0;
+ font-size: 12px;
+ color: var(--text-secondary);
+ cursor: pointer;
+ font-family: inherit;
+}
+
+.action-btn:hover {
+ color: var(--text-primary);
+ text-decoration: underline;
+}
+
+.action-btn.danger:hover {
+ color: #dc2626;
+}
+
+.branch-switch {
+ display: flex;
+ align-items: center;
+ gap: 2px;
+}
+
+.branch-btn {
+ background: none;
+ border: none;
+ cursor: pointer;
+ font-size: 15px;
+ line-height: 1;
+ color: var(--text-secondary);
+ padding: 0 3px;
+ font-family: inherit;
+}
+
+.branch-btn:disabled {
+ color: #d1d5db;
+ cursor: default;
+}
+
+.branch-btn:not(:disabled):hover {
+ color: var(--text-primary);
+}
+
+.branch-label {
+ font-size: 12px;
+ color: var(--text-secondary);
+ font-variant-numeric: tabular-nums;
+ min-width: 26px;
+ text-align: center;
+}
+
+.thinking-hint {
+ color: var(--text-muted);
+ font-size: 13.5px;
+}
+
+.edit-area {
+ margin-top: 4px;
+}
+
+.edit-actions {
+ display: flex;
+ justify-content: flex-end;
+ gap: 8px;
+ margin-top: 8px;
+}
+
+.message-note {
+ font-size: 12px;
+ color: var(--text-muted);
+ margin-top: 8px;
+ font-style: italic;
+}
+
+.message-note.error {
+ color: #dc2626;
+ font-style: normal;
+}
+
+.message-images {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ margin-bottom: 8px;
+}
+
+.message-image {
+ cursor: zoom-in;
+}
+
+/*
+ * 缂╃暐鍥惧昂瀵哥敱 AuthenticatedImage 鑷繁鐨� scoped 鏍峰紡鎺у埗 鈥斺��
+ * 杩欓噷鏄埗缁勪欢锛宻coped 灞炴�т綔鐢ㄤ笉鍒板瓙缁勪欢鍐呴儴鍏冪礌锛屽啓浜嗕篃涓嶇敓鏁堛��
+ * 鍙湪杩欓噷瀹氫箟銆岀偣寮�棰勮銆嶆椂鐨勮鐩栥��
+ */
+.message-image {
+ cursor: zoom-in;
+}
+
+.image-preview-modal {
+ width: auto;
+ max-width: 90vw;
+}
+
+/*
+ * 鏀惧ぇ棰勮锛氱敤 :deep 绌块�忓埌瀛愮粍浠跺唴閮ㄨ鐩栫缉鐣ュ浘涓婇檺銆�
+ * 鍚屾椂鏀惧紑瀹瑰櫒鐨� 160px 闄愬埗锛屽惁鍒欏浘鐗囦細琚鍣ㄥ崱浣忔斁涓嶅ぇ銆�
+ */
+.preview-large :deep(.authenticated-image) {
+ max-width: 86vw;
+ max-height: 82vh;
+}
+
+.preview-large :deep(.message-image-thumb) {
+ max-width: 86vw;
+ max-height: 82vh;
+ cursor: default;
+}
+
+.ocr-text {
+ margin-top: 8px;
+ font-size: 12px;
+}
+
+.ocr-toggle {
+ color: #0f766e;
+ cursor: pointer;
+}
+
+.ocr-toggle:hover {
+ text-decoration: underline;
+}
+
+.ocr-content {
+ margin: 6px 0 0;
+ padding: 8px 10px;
+ background: #f9fafb;
+ border: 1px solid var(--border-color);
+ border-radius: 6px;
+ white-space: pre-wrap;
+ word-break: break-word;
+ font-size: 12px;
+ color: var(--text-secondary);
+ max-height: 260px;
+ overflow-y: auto;
+}
+
+/* 鐢ㄦ埛娑堟伅閲岀殑鍥剧墖闈犲彸瀵归綈 */
+.message-item.role-user .message-images {
+ justify-content: flex-end;
+}
+
+.rag-sources {
+ margin-top: 12px;
+ padding: 10px 12px;
+ background: #f9fafb;
+ border: 1px solid var(--border-color);
+ border-radius: 8px;
+}
+
+.rag-sources-title {
+ font-size: 12px;
+ font-weight: 600;
+ color: var(--text-secondary);
+ margin-bottom: 6px;
+}
+
+.rag-source {
+ display: flex;
+ align-items: baseline;
+ gap: 7px;
+ font-size: 12px;
+ color: var(--text-secondary);
+ line-height: 1.75;
+ padding: 2px 0;
+}
+
+.rag-source-body {
+ flex: 1;
+ min-width: 0;
+}
+
+.rag-source-section {
+ color: var(--text-muted);
+ margin-left: 6px;
+ /* 绔犺妭鍚嶅彲鑳藉緢闀匡紝鍗曡鎴柇閬垮厤鎶婃潵婧愯鎾戞垚澶氳 */
+ display: inline-block;
+ max-width: 100%;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ vertical-align: bottom;
+}
+
+.rag-source-section::before {
+ content: '路';
+ margin-right: 6px;
+}
+
+/*
+ * 姝f枃閲岀殑寮曠敤缂栧彿楂樹寒銆�
+ * 涓庝笅鏂广�屽紩鐢ㄦ潵婧愩�嶅垪琛ㄧ殑 [1] 瑙嗚涓�鑷达紝鏂逛究鐢ㄦ埛瀵圭収鏍告煡銆�
+ */
+.message-content :deep(.citation-ref) {
+ color: #0f766e;
+ background: #ecfdf5;
+ border-radius: 3px;
+ padding: 0 3px;
+ font-size: 0.85em;
+ font-weight: 600;
+ cursor: help;
+ white-space: nowrap;
+}
+
+.rag-source-index {
+ color: var(--text-muted);
+ margin-right: 4px;
+}
+
+.rag-source-name {
+ color: var(--text-primary);
+}
+
+.rag-source-score {
+ color: var(--text-muted);
+ margin-left: 8px;
+}
+</style>
diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue
new file mode 100644
index 0000000..3c549fc
--- /dev/null
+++ b/src/components/Sidebar.vue
@@ -0,0 +1,498 @@
+<template>
+ <div class="sidebar">
+ <div class="sidebar-header">
+ <n-button class="new-chat-btn" block @click="handleNewChat">
+ <template #icon>
+ <span class="plus-icon">+</span>
+ </template>
+ 鏂板璇�
+ </n-button>
+ </div>
+
+ <div class="sidebar-search">
+ <n-input
+ v-model:value="keyword"
+ size="small"
+ clearable
+ placeholder="鎼滅储鍘嗗彶瀵硅瘽"
+ @input="handleSearchInput"
+ @keyup.esc="handleClearSearch"
+ >
+ <template #prefix>
+ <span class="search-icon">鈱�</span>
+ </template>
+ </n-input>
+ </div>
+
+ <div class="sidebar-list">
+ <!-- 鎼滅储鎬侊細鏄剧ず缁撴灉锛屽懡涓唴瀹规椂缁欏嚭涓婁笅鏂囩墖娈� -->
+ <template v-if="isSearching">
+ <n-spin v-if="chatStore.searching" size="small" class="sidebar-loading" />
+
+ <div v-else-if="visibleChats.length === 0" class="empty-hint sidebar-empty">
+ 娌℃湁鎵惧埌鍖归厤銆寋{ chatStore.searchKeyword }}銆嶇殑瀵硅瘽<br />
+ 璇曡瘯鍏朵粬鍏抽敭璇�
+ </div>
+
+ <div
+ v-for="chat in visibleChats"
+ v-else
+ :key="chat.id"
+ class="chat-item"
+ :class="{ active: chat.id === activeChatId }"
+ @click="$emit('select', chat.id)"
+ >
+ <div class="chat-item-main">
+ <div class="chat-title">{{ chat.title || '鏂板璇�' }}</div>
+ <!-- 鍛戒腑娑堟伅鍐呭鏃跺睍绀虹墖娈碉紝鏂逛究纭鏄笉鏄繖娆″璇� -->
+ <div v-if="chat.matchSnippet" class="chat-snippet">
+ {{ chat.matchSnippet }}
+ </div>
+ <div class="chat-meta">
+ <span>{{ chat.messageCount || 0 }} 鏉℃秷鎭�</span>
+ <span class="match-badge">{{ matchLabel(chat.matchType) }}</span>
+ </div>
+ </div>
+ </div>
+ </template>
+
+ <!-- 鏅�氭�� -->
+ <template v-else>
+ <n-spin v-if="loading" size="small" class="sidebar-loading" />
+
+ <div v-if="!loading && chats.length === 0" class="empty-hint sidebar-empty">
+ 杩樻病鏈夊璇�<br />鐐瑰嚮涓婃柟銆屾柊瀵硅瘽銆嶅紑濮�
+ </div>
+
+ <div
+ v-for="chat in chats"
+ :key="chat.id"
+ class="chat-item"
+ :class="{ active: chat.id === activeChatId }"
+ @click="$emit('select', chat.id)"
+ >
+ <div class="chat-item-main">
+ <!-- 鍙屽嚮杩涘叆閲嶅懡鍚嶏紝绗﹀悎妗岄潰绔枃浠剁鐞嗙殑鐩磋 -->
+ <n-input
+ v-if="editingId === chat.id"
+ ref="renameInputRef"
+ v-model:value="editingTitle"
+ size="tiny"
+ @blur="commitRename(chat)"
+ @keyup.enter="commitRename(chat)"
+ @keyup.esc="cancelRename"
+ @click.stop
+ />
+ <div v-else class="chat-title" @dblclick.stop="startRename(chat)">
+ {{ chat.title || '鏂板璇�' }}
+ </div>
+ <div class="chat-meta">
+ <span>{{ chat.messageCount || 0 }} 鏉℃秷鎭�</span>
+ <span v-if="chat.collectionNames?.length" class="chat-rag-tag">
+ 路 {{ chat.collectionNames.length }} 涓煡璇嗗簱
+ </span>
+ </div>
+ </div>
+
+ <n-dropdown
+ trigger="click"
+ :options="menuOptions"
+ @select="(key) => handleMenu(key, chat)"
+ >
+ <n-button text class="chat-more" @click.stop>鈰�</n-button>
+ </n-dropdown>
+ </div>
+ </template>
+ </div>
+
+ <div class="sidebar-footer">
+ <n-dropdown trigger="click" :options="userMenuOptions" @select="handleUserMenu">
+ <div class="user-info">
+ <div class="user-avatar">{{ avatarText }}</div>
+ <div class="user-text">
+ <div class="user-name">{{ auth.displayName }}</div>
+ <div class="user-role">{{ auth.isAdmin ? '绠$悊鍛�' : '鏅�氱敤鎴�' }}</div>
+ </div>
+ <span class="user-more">鈰�</span>
+ </div>
+ </n-dropdown>
+ </div>
+ </div>
+</template>
+
+<script setup>
+import { computed, nextTick, ref } from 'vue'
+import { NButton, NDropdown, NInput, NSpin, useDialog, useMessage } from 'naive-ui'
+import { useAuthStore } from '@/stores/authStore'
+import { useChatStore } from '@/stores/chatStore'
+
+const emit = defineEmits(['select', 'created', 'deleted', 'open-files', 'open-admin-knowledge'])
+
+const auth = useAuthStore()
+const chatStore = useChatStore()
+const message = useMessage()
+const dialog = useDialog()
+
+const loading = ref(false)
+const editingId = ref(null)
+const editingTitle = ref('')
+const renameInputRef = ref(null)
+
+/** 鎼滅储妗嗙殑鏈湴杈撳叆鍊硷紙涓� store 閲岀殑宸叉彁浜ゅ叧閿瘝鍖哄垎寮�锛� */
+const keyword = ref('')
+
+const chats = computed(() => chatStore.chats)
+const activeChatId = computed(() => chatStore.activeChatId)
+
+/** 鏄惁澶勪簬鎼滅储鎬侊細鍙鍏抽敭璇嶉潪绌哄氨鏄剧ず鎼滅储缁撴灉鑰岄潪瀹屾暣鍒楄〃 */
+const isSearching = computed(() => chatStore.searchKeyword.length > 0)
+
+/** 鎼滅储鎬佹樉绀虹粨鏋滃垪琛紝鏅�氭�佹樉绀哄叏閮ㄤ細璇� */
+const visibleChats = computed(() =>
+ isSearching.value ? chatStore.searchResults : chatStore.chats
+)
+
+/**
+ * 杈撳叆闃叉姈銆�
+ *
+ * 銆岃緭鍏ュ嵆鏌ャ�嶈嫢涓嶉槻鎶栵紝姣忔暡涓�涓瓧閮戒細鎵撲竴娆℃帴鍙o紝
+ * 鑰屼笖涓枃杈撳叆娉曞湪鎷奸煶闃舵涔熶細棰戠箒瑙﹀彂 input 浜嬩欢銆�
+ * 250ms 鏄墦瀛楀仠椤夸笌鍝嶅簲閫熷害涔嬮棿鐨勫父瑙佹姌涓��
+ */
+let searchTimer = null
+const SEARCH_DEBOUNCE_MS = 250
+
+function handleSearchInput() {
+ if (searchTimer) {
+ clearTimeout(searchTimer)
+ }
+ const value = keyword.value
+
+ if (!value || !value.trim()) {
+ // 娓呯┖鏃剁珛鍗虫仮澶嶅畬鏁村垪琛紝涓嶅繀绛夐槻鎶�
+ if (searchTimer) clearTimeout(searchTimer)
+ chatStore.clearSearch()
+ return
+ }
+
+ searchTimer = setTimeout(async () => {
+ try {
+ await chatStore.searchChats(value)
+ } catch (error) {
+ message.error(error.message || '鎼滅储澶辫触')
+ }
+ }, SEARCH_DEBOUNCE_MS)
+}
+
+function handleClearSearch() {
+ if (searchTimer) clearTimeout(searchTimer)
+ keyword.value = ''
+ chatStore.clearSearch()
+}
+
+/** 鍛戒腑绫诲瀷鏂囨 */
+function matchLabel(type) {
+ if (type === 'title') return '鏍囬鍛戒腑'
+ if (type === 'both') return '鏍囬+鍐呭'
+ return '鍐呭鍛戒腑'
+}
+
+const avatarText = computed(() => (auth.displayName || '?').charAt(0).toUpperCase())
+
+const menuOptions = [
+ { label: '閲嶅懡鍚�', key: 'rename' },
+ { label: '鐭ヨ瘑搴撹缃�', key: 'rag' },
+ { type: 'divider', key: 'd1' },
+ { label: '鍒犻櫎瀵硅瘽', key: 'delete' }
+]
+
+const userMenuOptions = computed(() => {
+ const options = [{ label: '鎴戠殑鐭ヨ瘑搴�', key: 'files' }]
+ // 绠$悊鍛橀澶栨彁渚涘叏灞�鐭ヨ瘑搴撶淮鎶ゅ叆鍙c��
+ // 鍚庣瀵� /api/files/global/upload 绛夌鐐瑰彟鏈� 403 鏍¢獙锛�
+ // 杩欓噷鐨勯殣钘忓彧鏄伩鍏嶆櫘閫氱敤鎴风湅鍒版棤鏉冮檺鐨勮彍鍗曢」銆�
+ if (auth.isAdmin) {
+ options.push({ label: '鍏ㄥ眬鐭ヨ瘑搴擄紙绠$悊鍛橈級', key: 'admin-knowledge' })
+ }
+ options.push({ type: 'divider', key: 'd1' })
+ options.push({ label: '閫�鍑虹櫥褰�', key: 'logout' })
+ return options
+})
+
+/** 鐢辩埗缁勪欢鍦ㄦ寕杞芥椂璋冪敤锛岄伩鍏嶇粍浠惰嚜宸辫Е鍙戣姹傞�犳垚鏃跺簭涓嶇‘瀹� */
+async function refresh() {
+ loading.value = true
+ try {
+ // 鍒锋柊浼氳瘽鍒楄〃鏃堕��鍑烘悳绱㈡�侊紝閬垮厤鍋滅暀鍦ㄦ棫缁撴灉涓�
+ handleClearSearch()
+ await chatStore.loadChats()
+ } catch (error) {
+ message.error(error.message || '鍔犺浇浼氳瘽鍒楄〃澶辫触')
+ } finally {
+ loading.value = false
+ }
+}
+
+async function handleNewChat() {
+ try {
+ const chat = await chatStore.createChat({})
+ emit('created', chat.id)
+ } catch (error) {
+ message.error(error.message || '鍒涘缓浼氳瘽澶辫触')
+ }
+}
+
+function startRename(chat) {
+ editingId.value = chat.id
+ editingTitle.value = chat.title
+ nextTick(() => {
+ // ref 鍦� v-for 涓細鏄暟缁�
+ const input = Array.isArray(renameInputRef.value)
+ ? renameInputRef.value[0]
+ : renameInputRef.value
+ input?.focus?.()
+ })
+}
+
+function cancelRename() {
+ editingId.value = null
+ editingTitle.value = ''
+}
+
+async function commitRename(chat) {
+ const title = editingTitle.value.trim()
+ // 娌℃敼鍔ㄦ垨涓虹┖鍒欐斁寮冿紝閬垮厤浜х敓绌烘爣棰�
+ if (!title || title === chat.title) {
+ cancelRename()
+ return
+ }
+ try {
+ await chatStore.renameChat(chat.id, title)
+ message.success('宸查噸鍛藉悕')
+ } catch (error) {
+ message.error(error.message || '閲嶅懡鍚嶅け璐�')
+ } finally {
+ cancelRename()
+ }
+}
+
+function handleMenu(key, chat) {
+ if (key === 'rename') {
+ startRename(chat)
+ } else if (key === 'rag') {
+ emit('select', chat.id)
+ emit('open-files')
+ } else if (key === 'delete') {
+ dialog.warning({
+ title: '鍒犻櫎瀵硅瘽',
+ content: `纭畾鍒犻櫎銆�${chat.title}銆嶅悧锛熻浼氳瘽鐨勬墍鏈夋秷鎭兘浼氳涓�骞跺垹闄わ紝涓旀棤娉曟仮澶嶃�俙,
+ positiveText: '鍒犻櫎',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await chatStore.removeChat(chat.id)
+ message.success('宸插垹闄�')
+ emit('deleted', chat.id)
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎澶辫触')
+ }
+ }
+ })
+ }
+}
+
+function handleUserMenu(key) {
+ if (key === 'files') {
+ emit('open-files')
+ } else if (key === 'admin-knowledge') {
+ emit('open-admin-knowledge')
+ } else if (key === 'logout') {
+ auth.logout()
+ emit('deleted', null)
+ }
+}
+
+defineExpose({ refresh })
+</script>
+
+<style scoped>
+.sidebar {
+ width: var(--sidebar-width);
+ height: 100vh;
+ background: var(--bg-sidebar);
+ border-right: 1px solid var(--border-color);
+ display: flex;
+ flex-direction: column;
+ flex-shrink: 0;
+}
+
+.sidebar-header {
+ padding: 12px;
+}
+
+.new-chat-btn {
+ justify-content: flex-start;
+ font-weight: 500;
+}
+
+.plus-icon {
+ font-size: 17px;
+ line-height: 1;
+}
+
+.sidebar-search {
+ padding: 0 12px 8px;
+}
+
+.search-icon {
+ font-size: 14px;
+ color: var(--text-muted);
+}
+
+.chat-snippet {
+ font-size: 11.5px;
+ color: var(--text-secondary);
+ margin-top: 3px;
+ /* 鐗囨鏈�澶氫袱琛岋紝瓒呭嚭鐢ㄧ渷鐣ュ彿鎴柇 */
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+ line-height: 1.5;
+}
+
+.match-badge {
+ color: #0f766e;
+ margin-left: 6px;
+}
+
+.sidebar-list {
+ flex: 1;
+ overflow-y: auto;
+ padding: 0 8px 8px;
+}
+
+.sidebar-loading {
+ display: flex;
+ justify-content: center;
+ padding: 20px 0;
+}
+
+.sidebar-empty {
+ padding: 28px 12px;
+ line-height: 1.9;
+}
+
+.chat-item {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ padding: 9px 10px;
+ border-radius: 8px;
+ cursor: pointer;
+ margin-bottom: 2px;
+ transition: background 0.12s ease;
+}
+
+.chat-item:hover {
+ background: var(--bg-hover);
+}
+
+.chat-item.active {
+ background: #e3e5e8;
+}
+
+.chat-item-main {
+ flex: 1;
+ min-width: 0;
+}
+
+.chat-title {
+ font-size: 13.5px;
+ font-weight: 500;
+ /* 鍗曡鎴柇锛岄伩鍏嶉暱鏍囬鎶婁晶杈规爮鎾戝紑 */
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.chat-meta {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 3px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.chat-rag-tag {
+ color: #6b7280;
+}
+
+.chat-more {
+ opacity: 0;
+ font-size: 16px;
+ line-height: 1;
+ padding: 0 4px;
+ color: var(--text-secondary);
+ transition: opacity 0.12s ease;
+}
+
+.chat-item:hover .chat-more {
+ opacity: 1;
+}
+
+.sidebar-footer {
+ border-top: 1px solid var(--border-color);
+ padding: 8px;
+}
+
+.user-info {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 8px;
+ border-radius: 8px;
+ cursor: pointer;
+}
+
+.user-info:hover {
+ background: var(--bg-hover);
+}
+
+.user-avatar {
+ width: 30px;
+ height: 30px;
+ border-radius: 50%;
+ background: #4b5563;
+ color: #fff;
+ font-size: 13px;
+ font-weight: 600;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+}
+
+.user-text {
+ flex: 1;
+ min-width: 0;
+}
+
+.user-name {
+ font-size: 13px;
+ font-weight: 500;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.user-role {
+ font-size: 11px;
+ color: var(--text-muted);
+}
+
+.user-more {
+ color: var(--text-muted);
+}
+</style>
diff --git a/src/main.js b/src/main.js
new file mode 100644
index 0000000..a48318b
--- /dev/null
+++ b/src/main.js
@@ -0,0 +1,19 @@
+import { createApp } from 'vue'
+import { createPinia } from 'pinia'
+
+import App from './App.vue'
+import router from './router'
+import { useAuthStore } from './stores/authStore'
+import './styles/global.css'
+
+const app = createApp(App)
+const pinia = createPinia()
+
+app.use(pinia)
+app.use(router)
+
+// 鍦ㄦ寕杞藉墠鎭㈠鏈湴淇濆瓨鐨勭櫥褰曠姸鎬併��
+// 蹇呴』鏃╀簬 router 棣栨瀵艰埅锛屽惁鍒欏埛鏂伴〉闈㈡椂璺敱瀹堝崼浼氳鍒や负鏈櫥褰曞苟鎶婄敤鎴疯涪鍥炵櫥褰曢〉銆�
+useAuthStore().restore()
+
+app.mount('#app')
diff --git a/src/router/index.js b/src/router/index.js
new file mode 100644
index 0000000..5b72b72
--- /dev/null
+++ b/src/router/index.js
@@ -0,0 +1,71 @@
+import { createRouter, createWebHistory } from 'vue-router'
+import { useAuthStore } from '@/stores/authStore'
+
+const routes = [
+ {
+ path: '/login',
+ name: 'login',
+ component: () => import('@/views/Login.vue'),
+ meta: { public: true, title: '鐧诲綍' }
+ },
+ {
+ // 鐢� /c/:chatId? 鑰屼笉鏄甫 query 鍙傛暟锛�
+ // 浼氳瘽 id 鏄〉闈㈣韩浠界殑涓�閮ㄥ垎锛屾斁璺緞閲屽埛鏂板拰鍒嗕韩閮芥洿鑷劧
+ path: '/c/:chatId?',
+ name: 'chat',
+ component: () => import('@/views/Chat.vue'),
+ meta: { title: '瀵硅瘽' }
+ },
+ {
+ path: '/files',
+ name: 'files',
+ component: () => import('@/views/Files.vue'),
+ meta: { title: '鐭ヨ瘑搴�' }
+ },
+ {
+ // 鍏ㄥ眬鐭ヨ瘑搴撶淮鎶わ細浠呯鐞嗗憳鍙銆�
+ // meta.adminOnly 鐢辫矾鐢卞畧鍗牎楠岋紱鍚庣鍙︽湁 403 鍏滃簳锛�
+ // 鍓嶇闅愯棌鍙槸浣撻獙浼樺寲锛屼笉鏄畨鍏ㄨ竟鐣屻��
+ path: '/admin/knowledge',
+ name: 'admin-knowledge',
+ component: () => import('@/views/AdminKnowledge.vue'),
+ meta: { title: '鍏ㄥ眬鐭ヨ瘑搴�', adminOnly: true }
+ },
+ { path: '/', redirect: '/c' },
+ { path: '/:pathMatch(.*)*', redirect: '/c' }
+]
+
+const router = createRouter({
+ history: createWebHistory(),
+ routes
+})
+
+/**
+ * 鍏ㄥ眬鍓嶇疆瀹堝崼锛氭湭鐧诲綍璁块棶鍙椾繚鎶ら〉闈㈡椂璺宠浆鐧诲綍椤点��
+ *
+ * 杩欓噷鍙仛銆屾湁娌℃湁 token銆嶇殑绮楀垽鏂紝涓嶆牎楠� token 鏄惁杩囨湡 鈥斺��
+ * 鐪熸鐨勬牎楠屼氦缁欏悗绔紙杩斿洖 401 鏃剁敱 axios 鎷︽埅鍣ㄧ粺涓�澶勭悊鐧诲嚭锛夈��
+ * 鍓嶇鏃犳硶鍙潬鍒ゆ柇 JWT 鏈夋晥鎬э紝纭瑙f瀽鍙細寮曞叆鏃堕挓鍋忓樊绛夐棶棰樸��
+ */
+router.beforeEach((to) => {
+ const auth = useAuthStore()
+ if (!to.meta.public && !auth.isLoggedIn) {
+ return { name: 'login', query: { redirect: to.fullPath } }
+ }
+ // 宸茬櫥褰曠敤鎴蜂笉搴斿啀鐪嬪埌鐧诲綍椤�
+ if (to.name === 'login' && auth.isLoggedIn) {
+ return { name: 'chat' }
+ }
+ // 绠$悊鍛樹笓灞為〉闈細闈炵鐞嗗憳鐩存帴鎸″洖鐭ヨ瘑搴撻〉銆�
+ // 娉ㄦ剰杩欏彧鏄槻姝㈣鍏ワ紝鐪熸鐨勬潈闄愭牎楠屽湪鍚庣锛堜細杩斿洖 403锛夈��
+ if (to.meta.adminOnly && !auth.isAdmin) {
+ return { name: 'files' }
+ }
+ return true
+})
+
+router.afterEach((to) => {
+ document.title = to.meta.title ? `${to.meta.title} 路 Custom-WebUI` : 'Custom-WebUI'
+})
+
+export default router
diff --git a/src/stores/authStore.js b/src/stores/authStore.js
new file mode 100644
index 0000000..f368f65
--- /dev/null
+++ b/src/stores/authStore.js
@@ -0,0 +1,127 @@
+import { defineStore } from 'pinia'
+import { computed, ref } from 'vue'
+import * as authApi from '@/api/authApi'
+import { setUnauthorizedHandler } from '@/api/axios'
+
+const TOKEN_KEY = 'webui_token'
+const USER_KEY = 'webui_user'
+
+/**
+ * 璁よ瘉鐘舵�併��
+ *
+ * token 瀛� localStorage 鏄潈琛″悗鐨勯�夋嫨锛�
+ * - 浼樼偣锛氬埛鏂伴〉闈笉涓㈢櫥褰曟�侊紝瀹炵幇绠�鍗�
+ * - 缂虹偣锛歑SS 涓�鏃﹀彂鐢燂紝token 鍙璇诲彇
+ * 鑻ュ畨鍏ㄨ姹傛洿楂橈紝搴旀敼涓恒�孒ttpOnly Cookie + CSRF Token銆嶆柟妗堬紝
+ * 浣嗛偅鏍峰氨闇�瑕佸悗绔敼閫犺璇佹柟寮忥紙褰撳墠鏄棤鐘舵�� JWT锛夈��
+ */
+export const useAuthStore = defineStore('auth', () => {
+ const token = ref('')
+ const user = ref(null)
+ const loading = ref(false)
+
+ const isLoggedIn = computed(() => Boolean(token.value))
+ const isAdmin = computed(() => user.value?.role === 'admin')
+ const displayName = computed(() => user.value?.username || '鏈櫥褰�')
+
+ /** 浠� localStorage 鎭㈠鐧诲綍鎬併�傚繀椤诲湪搴旂敤鎸傝浇鍓嶈皟鐢ㄣ�� */
+ function restore() {
+ const savedToken = localStorage.getItem(TOKEN_KEY)
+ if (savedToken) {
+ token.value = savedToken
+ }
+ const savedUser = localStorage.getItem(USER_KEY)
+ if (savedUser) {
+ try {
+ user.value = JSON.parse(savedUser)
+ } catch {
+ // 鏈湴鏁版嵁鎹熷潖锛屾竻鎺夐伩鍏嶅悗缁姤閿�
+ localStorage.removeItem(USER_KEY)
+ }
+ }
+ }
+
+ function persist() {
+ if (token.value) {
+ localStorage.setItem(TOKEN_KEY, token.value)
+ } else {
+ localStorage.removeItem(TOKEN_KEY)
+ }
+ if (user.value) {
+ localStorage.setItem(USER_KEY, JSON.stringify(user.value))
+ } else {
+ localStorage.removeItem(USER_KEY)
+ }
+ }
+
+ async function login(credentials) {
+ loading.value = true
+ try {
+ const data = await authApi.login(credentials)
+ token.value = data.token
+ user.value = data.user
+ persist()
+ return data
+ } finally {
+ loading.value = false
+ }
+ }
+
+ async function register(payload) {
+ loading.value = true
+ try {
+ return await authApi.register(payload)
+ } finally {
+ loading.value = false
+ }
+ }
+
+ /**
+ * 鐢ㄥ悗绔牎楠屾湰鍦� token 鏄惁浠嶇劧鏈夋晥銆�
+ *
+ * 鍓嶇鏃犳硶鍙潬鍒ゆ柇 JWT 杩囨湡鏃堕棿锛堟椂閽熷亸宸�佹棤绛惧悕鏍¢獙鑳藉姏锛夛紝
+ * 鍥犳鍒锋柊椤甸潰鍚庝富鍔ㄨ皟涓�娆� /auth/me锛歵oken 澶辨晥浼氳繑鍥� 401锛�
+ * 鐢� axios 鎷︽埅鍣ㄨЕ鍙� clear()銆�
+ */
+ async function fetchMe() {
+ if (!token.value) return null
+ try {
+ user.value = await authApi.fetchCurrentUser()
+ persist()
+ return user.value
+ } catch {
+ return null
+ }
+ }
+
+ /** 娓呯┖鐧诲綍鎬� */
+ function clear() {
+ token.value = ''
+ user.value = null
+ localStorage.removeItem(TOKEN_KEY)
+ localStorage.removeItem(USER_KEY)
+ }
+
+ function logout() {
+ clear()
+ }
+
+ // 鎶娿��401 鏃舵竻鐞嗙姸鎬併�嶆敞鍐岀粰 axios 鎷︽埅鍣ㄣ��
+ // 鐢ㄥ洖璋冩敞鍏ヨ�岄潪鍦� axios 閲� import store锛岄伩鍏嶅惊鐜緷璧栥��
+ setUnauthorizedHandler(() => clear())
+
+ return {
+ token,
+ user,
+ loading,
+ isLoggedIn,
+ isAdmin,
+ displayName,
+ restore,
+ login,
+ register,
+ fetchMe,
+ logout,
+ clear
+ }
+})
diff --git a/src/stores/chatStore.js b/src/stores/chatStore.js
new file mode 100644
index 0000000..d2cb46b
--- /dev/null
+++ b/src/stores/chatStore.js
@@ -0,0 +1,604 @@
+import { defineStore } from 'pinia'
+import { computed, reactive, ref } from 'vue'
+import * as chatApi from '@/api/chatApi'
+import { useAuthStore } from './authStore'
+import { streamChat as openSseStream } from '@/utils/sse'
+import {
+ branchPosition,
+ buildPath,
+ extractActiveChildIds,
+ flattenTree,
+ switchBranch as switchBranchSelection
+} from '@/utils/treeBuild'
+
+// 涔愯娑堟伅浣跨敤鐨勪复鏃� id銆傜敤璐熸暟閬垮厤涓庢湇鍔$鑷 id锛堟亽涓烘锛夊啿绐侊紝
+// 杩欐牱鏇挎崲鐪熷疄 id 鏃朵笉浼氬嚭鐜般�屼复鏃� id 鎭板ソ绛変簬鏌愭潯鐪熷疄娑堟伅 id銆嶇殑閿欎贡銆�
+let tempIdSeed = -1
+const nextTempId = () => tempIdSeed--
+
+/**
+ * 浼氳瘽涓庢秷鎭姸鎬併��
+ *
+ * ## 娑堟伅鏍戠殑鐘舵�佹ā鍨�
+ *
+ * 鍚庣杩斿洖宓屽鏍戯紝鎴戜滑棰濆缁存姢涓夋牱涓滆タ锛�
+ * - `tree` 鍘熷宓屽鏍戯紙鍞竴鏁版嵁婧愶紝鍙鎺ュ彛杩斿洖鍊艰鐩栵級
+ * - `nodeMap` 鎵佸钩绱㈠紩锛孫(1) 鏌ヤ换鎰忚妭鐐�
+ * - `selections` parentId -> 閫変腑鐨� childId锛岃褰曠敤鎴峰湪鍒嗘敮闂寸殑閫夋嫨
+ *
+ * 娓叉煋鐢ㄧ殑绾挎�ц矾寰勭敱 `path` 璁$畻灞炴�у疄鏃舵帹瀵硷紝涓嶅崟鐙瓨鍌� 鈥斺��
+ * 閬垮厤銆屾爲鏀逛簡浣嗚矾寰勬病鍚屾銆嶈繖绫荤粡鍏哥殑鐘舵�佷笉涓�鑷� bug銆�
+ */
+export const useChatStore = defineStore('chat', () => {
+ const chats = ref([])
+ const activeChatId = ref(null)
+ const tree = ref([])
+
+ /** parentId -> childId锛岀敤鎴风殑鍒嗘敮閫夋嫨 */
+ const selections = reactive({})
+
+ const streaming = ref(false)
+ const streamError = ref('')
+ /** 娴佸紡杩囩▼涓澧為噺鏇存柊鐨勬秷鎭� id锛岀敤浜� UI 楂樹寒銆屾鍦ㄨ緭鍏ャ�� */
+ const streamingMessageId = ref(null)
+
+ /** 褰撳墠 SSE 杩炴帴鐨勬帶鍒跺櫒锛岀敤浜庛�屽仠姝㈢敓鎴愩�� */
+ let streamController = null
+
+ const nodeMap = computed(() => flattenTree(tree.value))
+ const path = computed(() => buildPath(tree.value, selections))
+
+ const activeChat = computed(
+ () => chats.value.find((chat) => chat.id === activeChatId.value) || null
+ )
+
+ // ============================================================
+ // 浼氳瘽
+ // ============================================================
+
+ async function loadChats() {
+ chats.value = await chatApi.listChats()
+ return chats.value
+ }
+
+ // ---------------- 鎼滅储鍘嗗彶瀵硅瘽 ----------------
+
+ /** 鎼滅储鍏抽敭璇嶏紱涓虹┖琛ㄧず鏈浜庢悳绱㈡�� */
+ const searchKeyword = ref('')
+ /** 鎼滅储缁撴灉锛圕hatDTO 鏁扮粍锛屽甫 matchSnippet / matchType锛� */
+ const searchResults = ref([])
+ const searching = ref(false)
+ /**
+ * 璇锋眰搴忓彿銆�
+ *
+ * 鎼滅储鏄�岃緭鍏ュ嵆鏌ャ�嶏紝鎱㈢殑鏃ц姹傚彲鑳藉悗浜庢柊璇锋眰杩斿洖锛�
+ * 鐩存帴鎶婃棫缁撴灉鍐欒繘鍘诲氨浼氬嚭鐜般�岃緭鍏ヤ簡鏂拌瘝鍗存樉绀烘棫缁撴灉銆嶃��
+ * 姣忔鍙戣捣閫掑骞惰浣忓簭鍙凤紝鍥炴潵鏃跺涓嶄笂灏变涪寮冦��
+ */
+ let searchSeq = 0
+
+ async function searchChats(keyword) {
+ const kw = (keyword || '').trim()
+ searchKeyword.value = kw
+
+ if (!kw) {
+ searchResults.value = []
+ searching.value = false
+ return []
+ }
+
+ const seq = ++searchSeq
+ searching.value = true
+ try {
+ const results = await chatApi.searchChats(kw)
+ if (seq !== searchSeq) {
+ // 宸叉湁鏇存柊鐨勮姹傚彂鍑猴紝涓㈠純杩欐鐨勭粨鏋�
+ return searchResults.value
+ }
+ searchResults.value = Array.isArray(results) ? results : []
+ return searchResults.value
+ } catch (error) {
+ if (seq === searchSeq) {
+ searchResults.value = []
+ }
+ throw error
+ } finally {
+ if (seq === searchSeq) {
+ searching.value = false
+ }
+ }
+ }
+
+ /** 閫�鍑烘悳绱㈡�侊紝鎭㈠鏄剧ず瀹屾暣浼氳瘽鍒楄〃 */
+ function clearSearch() {
+ searchSeq++ // 璁╁湪閫旇姹傚け鏁�
+ searchKeyword.value = ''
+ searchResults.value = []
+ searching.value = false
+ }
+
+ async function createChat(payload = {}) {
+ const chat = await chatApi.createChat(payload)
+ // 鏂颁細璇濇彃鍒版渶鍓嶏紝绗﹀悎銆屾渶杩戞椿璺冨湪鏈�涓娿�嶇殑鎺掑簭绾﹀畾
+ chats.value.unshift(chat)
+ return chat
+ }
+
+ async function renameChat(chatId, title) {
+ const updated = await chatApi.updateChat(chatId, { title })
+ const index = chats.value.findIndex((chat) => chat.id === chatId)
+ if (index !== -1) {
+ // 鐢ㄦ浛鎹㈣�屼笉鏄� Object.assign锛氫繚璇佹墍鏈夊瓧娈甸兘涓庡悗绔竴鑷�
+ chats.value[index] = updated
+ }
+ return updated
+ }
+
+ async function updateChatMeta(chatId, meta) {
+ const updated = await chatApi.updateChat(chatId, { meta })
+ const index = chats.value.findIndex((chat) => chat.id === chatId)
+ if (index !== -1) {
+ chats.value[index] = updated
+ }
+ return updated
+ }
+
+ async function removeChat(chatId) {
+ await chatApi.deleteChat(chatId)
+ chats.value = chats.value.filter((chat) => chat.id !== chatId)
+
+ if (activeChatId.value === chatId) {
+ activeChatId.value = null
+ tree.value = []
+ clearSelections()
+ }
+ }
+
+ // ============================================================
+ // 娑堟伅鏍�
+ // ============================================================
+
+ function clearSelections() {
+ for (const key of Object.keys(selections)) {
+ delete selections[key]
+ }
+ }
+
+ /**
+ * 鍔犺浇浼氳瘽鐨勬秷鎭爲銆�
+ *
+ * @param {number} chatId
+ * @param {boolean} preserveSelections
+ * true 鏃朵繚鐣欑敤鎴峰凡鏈夌殑鍒嗘敮閫夋嫨锛堟祦寮忕粨鏉熷悗鍒锋柊鐢級锛�
+ * false 鏃舵寜鍚庣缁欑殑 activeChildId 閲嶅缓锛堝垏鎹細璇濈敤锛夈��
+ */
+ async function loadMessages(chatId, preserveSelections = false) {
+ const previous = preserveSelections ? { ...selections } : null
+
+ const data = await chatApi.listMessages(chatId)
+ tree.value = Array.isArray(data) ? data : []
+ activeChatId.value = chatId
+
+ clearSelections()
+ Object.assign(selections, extractActiveChildIds(tree.value))
+
+ // 淇濈暀鐢ㄦ埛鐨勯�夋嫨锛氱敤鎴锋墜鍔ㄥ垏鍒板垎鏀� 1 鍚庯紝鍒锋柊娑堟伅涓嶅簲璺冲洖鍒嗘敮 2
+ if (previous) {
+ for (const [parentId, childId] of Object.entries(previous)) {
+ const node = nodeMap.value.get(Number(parentId))
+ if (node?.children?.some((child) => child.id === Number(childId))) {
+ selections[parentId] = Number(childId)
+ }
+ }
+ }
+
+ return tree.value
+ }
+
+ /** 鍒囨崲鏌愪釜澶氬垎鏀妭鐐逛笅閫変腑鐨勫瓙鍒嗘敮 */
+ function switchBranch(message, delta) {
+ return switchBranchSelection(message, delta, selections)
+ }
+
+ /** 鏌ヨ鏌愪釜鑺傜偣褰撳墠鏄剧ず绗嚑涓垎鏀� */
+ function getBranchPosition(message) {
+ return branchPosition(message, selections)
+ }
+
+ /** 鎶婁竴鏉℃秷鎭寕鍒版寚瀹氱埗鑺傜偣涓嬶紙鐢ㄤ簬涔愯娓叉煋锛� */
+ function appendMessage(message, parentId) {
+ if (parentId == null) {
+ tree.value.push(message)
+ return
+ }
+ const parent = nodeMap.value.get(parentId)
+ if (!parent) {
+ // 鐖惰妭鐐逛笉鍦ㄥ綋鍓嶆爲閲岋紙鐞嗚涓婁笉璇ュ彂鐢燂級锛岄��鍖栦负杩藉姞鍒版牴锛屼繚璇佹秷鎭笉涓�
+ tree.value.push(message)
+ return
+ }
+ if (!Array.isArray(parent.children)) {
+ parent.children = []
+ }
+ parent.children.push(message)
+ // 鏂版秷鎭粯璁ゆ垚涓鸿鐖惰妭鐐逛笅鐨勬椿璺冨垎鏀�
+ selections[parentId] = message.id
+ }
+
+ /** 鐢ㄧ湡瀹� id 鏇挎崲涔愯娑堟伅鐨勪复鏃� id */
+ function replaceMessageId(tempId, realId) {
+ for (const node of nodeMap.value.values()) {
+ if (node.id === tempId) {
+ node.id = realId
+ break
+ }
+ }
+ for (const [parentId, childId] of Object.entries(selections)) {
+ if (childId === tempId) {
+ selections[parentId] = realId
+ }
+ }
+ }
+
+ /** 澧為噺杩藉姞娴佸紡鍐呭 */
+ function appendContent(messageId, delta) {
+ const node = nodeMap.value.get(messageId)
+ if (node) {
+ node.content = (node.content || '') + delta
+ }
+ }
+
+ /** 娴佺粨鏉熸椂鐢ㄥ畬鏁村唴瀹规牎鍑嗭紙闃叉缃戠粶涓㈠潡瀵艰嚧鍐呭涓嶄竴鑷达級 */
+ function finalizeMessage(messageId, content, sources) {
+ const node = nodeMap.value.get(messageId)
+ if (!node) return
+ node.done = true
+ if (typeof content === 'string' && content.length > 0) {
+ node.content = content
+ }
+ if (Array.isArray(sources) && sources.length > 0) {
+ node.sources = sources
+ }
+ }
+
+ function markMessageFailed(messageId, reason) {
+ const node = nodeMap.value.get(messageId)
+ if (!node) return
+ node.done = true
+ node.failed = true
+ if (!node.content) {
+ node.content = `锛堢敓鎴愬け璐ワ細${reason}锛塦
+ }
+ }
+
+ async function editMessage(chatId, messageId, content) {
+ await chatApi.updateMessage(chatId, messageId, { content })
+ const node = nodeMap.value.get(messageId)
+ if (node) {
+ node.content = content
+ }
+ }
+
+ async function removeMessage(chatId, messageId) {
+ await chatApi.deleteMessage(chatId, messageId)
+ await loadMessages(chatId, true)
+ }
+
+ // ============================================================
+ // 娴佸紡瀵硅瘽
+ // ============================================================
+
+ /**
+ * 鍙戦�佷竴鏉℃秷鎭苟鎺ユ敹娴佸紡鍥炲銆�
+ *
+ * 鏃跺簭锛�
+ * 1. 绔嬪嵆鎻掑叆涓存椂 user 娑堟伅 + 绌� assistant 姘旀场锛堜箰瑙傛覆鏌擄紝闆跺欢杩熷弽棣堬級
+ * 2. 寤虹珛 SSE 杩炴帴
+ * 3. start 浜嬩欢鍒拌揪 鈫� 鎶婁复鏃� id 鎹㈡垚鏈嶅姟绔湡瀹� id
+ * 4. delta 浜嬩欢 鈫� 杩藉姞鏂囨湰
+ * 5. done 浜嬩欢 鈫� 鏍″噯鍐呭骞堕噸鏂板姞杞芥暣妫垫爲锛堟嬁鍒版湇鍔$鏉冨▉缁撴瀯锛�
+ *
+ * @param {object} options
+ * @param {number} options.chatId
+ * @param {string} options.content
+ * @param {number|null} [options.parentId] 鎸傝浇鐐癸紱涓虹┖琛ㄧず鎺ュ湪褰撳墠鍒嗘敮鏈熬
+ * @param {string|null} [options.model]
+ * @param {boolean} [options.useRag]
+ * @returns {Promise<void>}
+ */
+ async function sendMessage({
+ chatId,
+ content,
+ parentId = null,
+ model = null,
+ useRag = true,
+ imageText = null,
+ imageTextId = null,
+ imageFileIds = null
+ }) {
+ if (streaming.value) {
+ throw new Error('涓婁竴鏉″洖澶嶈繕鍦ㄧ敓鎴愪腑锛岃绋嶅�欐垨鍏堝仠姝㈢敓鎴�')
+ }
+ // 鍏佽銆屽彧鍙戝浘鐗囥�佷笉鎵撳瓧銆嶏細姝ゆ椂鍐呭涓虹┖浣嗗浘鐗囧瓨鍦�
+ const hasImages = Array.isArray(imageFileIds) && imageFileIds.length > 0
+ if ((!content || !content.trim()) && !hasImages) {
+ throw new Error('娑堟伅鍐呭涓嶈兘涓虹┖')
+ }
+
+ streamError.value = ''
+
+ // 纭畾鎸傝浇鐐癸細鏄惧紡浼犲叆浼樺厛锛屽惁鍒欏彇褰撳墠娓叉煋璺緞鐨勬渶鍚庝竴涓妭鐐�
+ const effectiveParentId =
+ parentId ?? (path.value.length > 0 ? path.value[path.value.length - 1].id : null)
+
+ // ---- 涔愯娓叉煋 ----
+ const tempUserId = nextTempId()
+ const tempAssistantId = nextTempId()
+ const now = new Date().toISOString()
+ // 鍥剧墖涓虹┖鏃朵紶 null锛岄伩鍏嶅悗绔敹鍒扮┖鏁扮粍杩樺幓鍐� metadata
+ const effectiveImageIds = hasImages ? imageFileIds : null
+
+ appendMessage(
+ {
+ id: tempUserId,
+ chatId,
+ parentId: effectiveParentId,
+ role: 'user',
+ content,
+ done: true,
+ pending: true,
+ createdAt: now,
+ // 涔愯娓叉煋闃舵灏辨妸鍥剧墖鎸備笂锛岀敤鎴风珛鍒荤湅鍒拌嚜宸卞彂鍑哄幓鐨勫浘
+ imageFileIds: effectiveImageIds,
+ children: []
+ },
+ effectiveParentId
+ )
+
+ appendMessage(
+ {
+ id: tempAssistantId,
+ chatId,
+ parentId: tempUserId,
+ role: 'assistant',
+ content: '',
+ done: false,
+ pending: true,
+ createdAt: now,
+ children: []
+ },
+ tempUserId
+ )
+
+ streaming.value = true
+ streamingMessageId.value = tempAssistantId
+
+ // 璁板綍 id 鏄犲皠锛屼緵浜嬩欢鍥炶皟浣跨敤
+ let userId = tempUserId
+ let assistantId = tempAssistantId
+
+ const auth = useAuthStore()
+
+ const query = new URLSearchParams({ content, useRag: String(useRag) })
+ // 浼樺厛鐢ㄦ殏瀛� id锛氶暱鏂囨湰璧� query 浼氳Е鍙� Tomcat 璇锋眰琛屼笂闄�
+ if (imageTextId) {
+ query.set('imageTextId', imageTextId)
+ } else if (imageText) {
+ query.set('imageText', imageText)
+ }
+ if (effectiveImageIds) {
+ // 鍚庣鐢� List<Long> 鎺ユ敹锛岄噸澶� key 鍗冲涓��
+ effectiveImageIds.forEach((id) => query.append('imageFileIds', String(id)))
+ }
+ if (effectiveParentId != null) {
+ query.set('parentId', String(effectiveParentId))
+ }
+ if (model) {
+ query.set('model', model)
+ }
+
+ return new Promise((resolve) => {
+ streamController = openSseStream({
+ url: `/api/chats/${chatId}/stream?${query.toString()}`,
+ token: auth.token,
+
+ onEvent(eventName, payload) {
+ switch (eventName) {
+ case 'start': {
+ // 鐢ㄦ湇鍔$鐪熷疄 id 鏇挎崲涓存椂 id
+ if (payload.userMessageId) {
+ replaceMessageId(userId, payload.userMessageId)
+ userId = payload.userMessageId
+ }
+ if (payload.messageId) {
+ replaceMessageId(assistantId, payload.messageId)
+ assistantId = payload.messageId
+ streamingMessageId.value = assistantId
+ }
+ if (payload.model) {
+ const node = nodeMap.value.get(assistantId)
+ if (node) node.model = payload.model
+ }
+ break
+ }
+
+ case 'delta': {
+ appendContent(assistantId, payload.delta || '')
+ break
+ }
+
+ case 'title': {
+ // 鍚庣鑷姩鐢熸垚浜嗕細璇濇爣棰橈紝鍚屾鍒颁晶杈规爮
+ const chat = chats.value.find((item) => item.id === chatId)
+ if (chat && payload.title) {
+ chat.title = payload.title
+ }
+ break
+ }
+
+ case 'done': {
+ finalizeMessage(assistantId, payload.content, payload.sources)
+ break
+ }
+
+ case 'error': {
+ streamError.value = payload.error || '鐢熸垚澶辫触'
+ markMessageFailed(assistantId, streamError.value)
+ break
+ }
+
+ default:
+ break
+ }
+ },
+
+ onError(error) {
+ streamError.value = error.message
+ markMessageFailed(assistantId, error.message)
+ },
+
+ async onClose() {
+ // 鏀跺熬蹇呴』鏃犳潯浠舵仮澶嶃�屽彲鍙戦�併�嶇姸鎬併��
+ // 涔嬪墠杩欓噷渚濊禆 sse.js 涓�瀹氬洖璋� onClose锛涗竴鏃﹀紓甯歌矾寰勬紡鎺夊洖璋冿紝
+ // streaming 灏卞崱鍦� true锛屽彂閫佹寜閽案涔呭彉鐏帮紝鍙兘鍒锋柊椤甸潰銆�
+ // sse.js 鐜板湪淇濊瘉 onClose 鎭板ソ瑙﹀彂涓�娆★紝杩欓噷鍐嶇‘淇濇敹灏鹃�昏緫鏈韩
+ // 涓嶄細鍥犱负涓棿鏌愭鎶涢敊鑰屾彁鍓嶄腑鏂��
+ streaming.value = false
+ streamingMessageId.value = null
+ streamController = null
+
+ // 涔愯娑堟伅鐨� pending 鏍囪璇ユ竻鎺変簡
+ for (const node of nodeMap.value.values()) {
+ if (node.pending) node.pending = false
+ }
+
+ // 閲嶆柊鎷夊彇鏁存5鏍戯紝鎷垮埌鏈嶅姟绔殑鏉冨▉缁撴瀯锛堝惈鐪熸鐨� id銆乨one 鐘舵�併��
+ // 浠ュ強棣栨潯鎻愰棶鐢熸垚鐨勬爣棰橈級銆備繚鐣欑敤鎴风殑鍒嗘敮閫夋嫨锛岄伩鍏嶈鍥捐烦鍔ㄣ��
+ //
+ // 浣嗗彧鏈夈�岀敤鎴蜂粛鐒跺仠鐣欏湪鏈娴佹墍灞炵殑浼氳瘽銆嶆椂鎵嶅埛鏂帮細
+ // 鑻ョ敤鎴峰湪鐢熸垚杩囩▼涓垏鍒颁簡鍒殑浼氳瘽锛岃繖閲岀殑 loadMessages(chatId)
+ // 浼氭妸鏂颁細璇濈殑娑堟伅鏍戣鐩栨垚鏃т細璇濈殑锛屽睘浜庡吀鍨嬬殑寮傛绔炴�併��
+ try {
+ if (activeChatId.value === chatId) {
+ await loadMessages(chatId, true)
+ }
+ await loadChats()
+ } catch {
+ // 鍒锋柊澶辫触涓嶅奖鍝嶅凡娓叉煋鐨勫唴瀹癸紝闈欓粯澶勭悊
+ }
+
+ resolve()
+ }
+ })
+ })
+ }
+
+ /**
+ * 閲嶆柊鐢熸垚锛氫互鏌愭潯 user 娑堟伅涓虹埗鑺傜偣锛屽啀鐢熸垚涓�涓� assistant 鍒嗘敮銆�
+ *
+ * 杩欐槸娑堟伅鏍戙�屽垎鏀�嶈兘鍔涚殑鍏ュ彛 鈥斺�� 鏂板洖澶嶄細鎴愪负宸叉湁鍥炲鐨勫厔寮熻妭鐐癸紝
+ * 鍓嶇鐢ㄥ垎鏀垏鎹㈠櫒鍦ㄥ畠浠箣闂村垏鎹€��
+ */
+ async function regenerate({ chatId, userMessageId, model = null, useRag = true }) {
+ const userNode = nodeMap.value.get(userMessageId)
+ if (!userNode) {
+ throw new Error('鎵句笉鍒拌閲嶆柊鐢熸垚鐨勬秷鎭�')
+ }
+ if (!userNode.content) {
+ throw new Error('璇ユ秷鎭唴瀹逛负绌猴紝鏃犳硶閲嶆柊鐢熸垚')
+ }
+
+ // parentId 浼� user 娑堟伅鏈韩锛屽悗绔細鎶婃柊 assistant 鎸傚湪瀹冧笅闈紝
+ // 浠庤�屼笌鏃㈡湁鐨� assistant 鍥炲褰㈡垚鍏勫紵鍏崇郴
+ // 鎶婂師娑堟伅鐨勫浘鐗囦竴骞跺甫涓婏紝鍚﹀垯閲嶆柊鐢熸垚浼氫涪鎺夊浘鐗囦笂涓嬫枃锛�
+ // 鍚屼竴涓棶棰樺嵈寰楀埌銆屼笉鐭ラ亾浣犲湪璇翠粈涔堛�嶇殑鍥炵瓟
+ return sendMessage({
+ chatId,
+ content: userNode.content,
+ parentId: userMessageId,
+ model,
+ useRag,
+ imageText: userNode.imageText || null,
+ // 鍘熸秷鎭惤搴撴椂瀛樼殑鏄枃瀛楁湰韬紝閲嶆柊鐢熸垚鏃堕噸鏂版殏瀛樻崲鍙栨柊 id
+ imageTextId: null,
+ imageFileIds: userNode.imageFileIds || null
+ })
+ }
+
+ /**
+ * 涓诲姩鍋滄鐢熸垚銆�
+ *
+ * 涓柇杩炴帴浼氳鍚庣鐨� onCompletion/onError 瑙﹀彂锛岄偅閲屼細 cancel 鎺夌敓鎴愮嚎绋�
+ * 骞堕噴鏀� SseEmitter 鈥斺�� 杩欐槸闃叉硠婕忕殑鍏抽敭璺緞銆�
+ */
+ function stopStreaming() {
+ // 鍏堟妸鎺у埗鍣ㄦ憳涓嬫潵锛岄伩鍏� abort() 瑙﹀彂鐨勫洖璋冿紙onClose锛夐噷鍐嶆璁块棶瀹�
+ const controller = streamController
+ streamController = null
+
+ // 绔嬪嵆鏃犳潯浠舵仮澶嶅彲鍙戦�佺姸鎬併��
+ // 椤哄簭寰堝叧閿細蹇呴』鍦� abort() 涔嬪墠灏辨妸 streaming 缃� false銆�
+ // abort() 浼氬悓姝ヨЕ鍙� sse.js 鐨� onClose锛岃�� onClose 鍐呴儴杩樻湁涓�姝�
+ // 銆岄噸鏂版媺鍙栨秷鎭爲銆嶇殑 async 閫昏緫锛涜嫢鎶婂畠褰撲綔鎭㈠ streaming 鐨勫敮涓�
+ // 閫斿緞锛屼竴鏃﹁鍥炶皟鍥犱负浠讳綍鍘熷洜娌¤蛋鍒帮紙渚嬪鍒囦細璇濇椂琚珵鎬佹墦鏂級锛�
+ // streaming 灏变細姘镐箙鍗″湪 true锛屽彂閫佹寜閽彉鐏颁笖鍙兘鍒锋柊椤甸潰銆�
+ streaming.value = false
+ streamingMessageId.value = null
+
+ if (controller) {
+ controller.abort()
+ }
+
+ // 鎶婁粛鍦ㄧ敓鎴愪腑鐨勬皵娉℃爣璁颁负宸插畬鎴愶紝閬垮厤涓�鐩存樉绀恒�岃緭鍏ヤ腑銆�
+ for (const node of nodeMap.value.values()) {
+ if (node.pending) node.pending = false
+ if (node.done === false && node.role === 'assistant') {
+ node.done = true
+ node.stopped = true
+ }
+ }
+ }
+
+ /** 鍒囨崲浼氳瘽鏃舵竻绌哄綋鍓嶈鍥剧姸鎬� */
+ function resetView() {
+ stopStreaming()
+ tree.value = []
+ clearSelections()
+ streamError.value = ''
+ }
+
+ return {
+ // state
+ chats,
+ activeChatId,
+ tree,
+ streaming,
+ streamError,
+ streamingMessageId,
+ selections,
+ // getters
+ nodeMap,
+ path,
+ activeChat,
+ // actions
+ loadChats,
+ searchKeyword,
+ searchResults,
+ searching,
+ searchChats,
+ clearSearch,
+ createChat,
+ renameChat,
+ updateChatMeta,
+ removeChat,
+ loadMessages,
+ switchBranch,
+ getBranchPosition,
+ editMessage,
+ removeMessage,
+ sendMessage,
+ regenerate,
+ stopStreaming,
+ resetView
+ }
+})
diff --git a/src/styles/global.css b/src/styles/global.css
new file mode 100644
index 0000000..ace5258
--- /dev/null
+++ b/src/styles/global.css
@@ -0,0 +1,220 @@
+:root {
+ --sidebar-width: 268px;
+ --border-color: #e5e7eb;
+ --bg-page: #ffffff;
+ --bg-sidebar: #f7f7f8;
+ --bg-hover: #ececf1;
+ --text-primary: #1f2937;
+ --text-secondary: #6b7280;
+ --text-muted: #9ca3af;
+ --bubble-user: #f1f5f9;
+ --bubble-assistant: #ffffff;
+ --code-bg: #f6f8fa;
+}
+
+* {
+ box-sizing: border-box;
+}
+
+html,
+body {
+ margin: 0;
+ padding: 0;
+ height: 100%;
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
+ 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
+ color: var(--text-primary);
+ background: var(--bg-page);
+ -webkit-font-smoothing: antialiased;
+}
+
+/* ---------------- 婊氬姩鏉★細缁嗕竴浜涳紝鍑忓皯瑙嗚鍣煶 ---------------- */
+::-webkit-scrollbar {
+ width: 8px;
+ height: 8px;
+}
+
+::-webkit-scrollbar-track {
+ background: transparent;
+}
+
+::-webkit-scrollbar-thumb {
+ background: #d1d5db;
+ border-radius: 4px;
+}
+
+::-webkit-scrollbar-thumb:hover {
+ background: #9ca3af;
+}
+
+/* ---------------- 娑堟伅姝f枃鎺掔増 ---------------- */
+/*
+ * 娑堟伅姝f枃锛歁arkdown 娓叉煋鍚庣殑鏍峰紡銆�
+ *
+ * 娉ㄦ剰杩欓噷**涓嶈兘**鍐嶇敤 `white-space: pre-wrap` 鈥斺��
+ * 閭f槸銆屾寜绾枃鏈樉绀恒�嶆椂浠g殑鍐欐硶锛岀敤鏉ヤ繚鐣欏師鏂囨崲琛屻��
+ * 鐜板湪鍐呭宸茬粡鏄� <p>/<pre>/<li> 杩欎簺鍧楃骇鍏冪礌锛宲re-wrap 浼氾細
+ * 1. 鎶� HTML 婧愮爜閲岀殑缂╄繘涓庢崲琛屼篃娓叉煋鍑烘潵锛屾钀戒箣闂村嚭鐜拌帿鍚嶇┖琛�
+ * 2. 璁� <pre> 鐨勬崲琛岃閲嶅璁$畻锛屼唬鐮佸潡琛岃窛缈诲��
+ * 鎹㈣鐜板湪鐢� Markdown 鑷繁璐熻矗锛坢arked 鐨� breaks: true 鎶婂崟鎹㈣杞� <br>锛夈��
+ */
+.message-content {
+ line-height: 1.75;
+ word-break: break-word;
+ overflow-wrap: anywhere;
+}
+
+/* 娈佃惤涔嬮棿鐣欏嚭闂磋窛锛屽悓鏃跺幓鎺夐灏惧浣欑┖闅欙紝閬垮厤姘旀场涓婁笅琚拺寮� */
+.message-content > :first-child {
+ margin-top: 0;
+}
+
+.message-content > :last-child {
+ margin-bottom: 0;
+}
+
+.message-content p {
+ margin: 0 0 10px;
+}
+
+.message-content h1,
+.message-content h2,
+.message-content h3,
+.message-content h4,
+.message-content h5,
+.message-content h6 {
+ margin: 16px 0 8px;
+ font-weight: 600;
+ line-height: 1.4;
+}
+
+.message-content h1 { font-size: 1.5em; }
+.message-content h2 { font-size: 1.3em; }
+.message-content h3 { font-size: 1.15em; }
+.message-content h4,
+.message-content h5,
+.message-content h6 { font-size: 1em; }
+
+.message-content ul,
+.message-content ol {
+ margin: 0 0 10px;
+ padding-left: 1.6em;
+}
+
+.message-content li {
+ margin: 3px 0;
+}
+
+.message-content blockquote {
+ margin: 0 0 10px;
+ padding: 2px 0 2px 12px;
+ border-left: 3px solid #d1d5db;
+ color: var(--text-secondary);
+}
+
+.message-content hr {
+ border: none;
+ border-top: 1px solid var(--border-color);
+ margin: 14px 0;
+}
+
+/* 琛屽唴浠g爜 */
+.message-content code {
+ background: var(--code-bg);
+ padding: 2px 5px;
+ border-radius: 4px;
+ font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
+ font-size: 0.9em;
+}
+
+/*
+ * 浠g爜鍧椼�傛敞鎰忚鍐欏湪琛屽唴浠g爜瑙勫垯**涔嬪悗**骞惰鐩� background/padding锛�
+ * 鍚﹀垯 <pre><code> 浼氬悓鏃跺懡涓袱鏉¤鍒欙紝鍑虹幇銆屽潡閲屽張濂椾簡涓�灞傚簳鑹层�嶃��
+ */
+.message-content pre {
+ background: #f6f8fa;
+ border: 1px solid var(--border-color);
+ border-radius: 8px;
+ padding: 12px 14px;
+ margin: 0 0 10px;
+ /* 浠g爜涓嶆崲琛岋紝杩囬暱鏃舵í鍚戞粴鍔紱绾靛悜浜ょ粰澶栧眰娑堟伅鍒楄〃 */
+ overflow-x: auto;
+ line-height: 1.6;
+}
+
+.message-content pre code {
+ background: none;
+ padding: 0;
+ border-radius: 0;
+ font-size: 12.5px;
+ white-space: pre;
+}
+
+/* 琛ㄦ牸 */
+.message-content table {
+ border-collapse: collapse;
+ margin: 0 0 10px;
+ display: block;
+ overflow-x: auto;
+ max-width: 100%;
+}
+
+.message-content th,
+.message-content td {
+ border: 1px solid var(--border-color);
+ padding: 6px 10px;
+ text-align: left;
+}
+
+.message-content th {
+ background: #f9fafb;
+ font-weight: 600;
+}
+
+.message-content a {
+ color: #0f766e;
+ text-decoration: none;
+}
+
+.message-content a:hover {
+ text-decoration: underline;
+}
+
+/* ---------------- 鎵撳瓧鍏夋爣 ---------------- */
+.typing-cursor::after {
+ content: '鈻�';
+ margin-left: 1px;
+ animation: blink 1s step-end infinite;
+ color: var(--text-secondary);
+}
+
+@keyframes blink {
+ 0%,
+ 100% {
+ opacity: 1;
+ }
+ 50% {
+ opacity: 0;
+ }
+}
+
+/* ---------------- 閫氱敤宸ュ叿绫� ---------------- */
+.text-secondary {
+ color: var(--text-secondary);
+}
+
+.text-muted {
+ color: var(--text-muted);
+}
+
+.flex-center {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.empty-hint {
+ color: var(--text-muted);
+ font-size: 13px;
+ text-align: center;
+}
diff --git a/src/utils/markdown.js b/src/utils/markdown.js
new file mode 100644
index 0000000..510fb67
--- /dev/null
+++ b/src/utils/markdown.js
@@ -0,0 +1,209 @@
+import { marked } from 'marked'
+import DOMPurify from 'dompurify'
+
+/**
+ * 娑堟伅姝f枃鐨� Markdown 娓叉煋銆�
+ *
+ * ## 涓轰粈涔堥渶瑕併�屽厛杞箟鍐嶈В鏋愩�嶈繖涓『搴�
+ *
+ * 妯″瀷杈撳嚭鏄�**涓嶅彲淇″唴瀹�** 鈥斺�� 瀹冨彲鑳藉寘鍚� `<script>`銆乣<img onerror=...>`
+ * 杩欑被鍘熷 HTML銆傚父瑙佸仛娉曟槸銆屽厛浜ょ粰 marked 瑙f瀽锛屽啀鐢� DOMPurify 娓呮礂銆嶏紝
+ * 浣嗛偅鎰忓懗鐫�鍗遍櫓 HTML 鑷冲皯琚В鏋愯繘杩� DOM 涓�娆★紝娓呮礂瑙勫垯涓�鏃︽湁鐤忔紡灏变腑鎷涖��
+ *
+ * 杩欓噷閲囩敤鏇翠繚瀹堢殑椤哄簭锛�
+ * 1. 鍏堟妸鍘熸枃閲岀殑 `& < > " '` 鍏ㄩ儴杞箟鎴愬疄浣�
+ * 2. 鍐嶄氦缁� marked 瑙f瀽鎴� HTML
+ * 3. 鏈�鍚� DOMPurify 鍏滃簳锛堥槻寰� marked 鑷韩鍙兘寮曞叆鐨勯棶棰橈級
+ *
+ * 杞箟鍚庢ā鍨嬪啓鐨� `<div>` 鍙樻垚 `<div>`锛宮arked 鍙妸瀹冨綋鏅�氭枃瀛楋紝
+ * 姘歌繙涓嶄細娓叉煋鎴愭爣绛俱�備唬浠锋槸妯″瀷杈撳嚭閲岀殑鍘熷 HTML 涓嶇敓鏁� 鈥斺��
+ * 瀵硅亰澶╁満鏅繖姝f槸鎴戜滑鎯宠鐨勩��
+ *
+ * ## 鍏充簬寮曠敤缂栧彿 [1]
+ *
+ * Markdown 浼氭妸 `[1]` 褰撴垚銆屽紩鐢ㄥ紡閾炬帴銆嶇殑璇硶锛堝悗闈㈡病鏈� `:` 瀹氫箟鏃�
+ * 澶氭暟瀹炵幇鍘熸牱杈撳嚭锛屼絾杩欏睘浜庢湭瀹氫箟琛屼负锛夈�備负閬垮厤渚濊禆杩欑杈圭晫琛屼负锛�
+ * 寮曠敤楂樹寒**鍦� Markdown 娓叉煋瀹屾垚鍚�**瀵圭敓鎴愮殑 HTML 鍋氾紝骞惰烦杩� `<code>`
+ * 涓� `<pre>` 鍐呴儴锛岄伩鍏嶆妸浠g爜閲岀殑鏁扮粍涓嬫爣璇爣鎴愬紩鐢ㄣ��
+ */
+
+// 璇簭锛欸FM锛堣〃鏍笺�佸垹闄ょ嚎銆佷换鍔″垪琛級+ 鍗曟崲琛岃浆 <br>锛堟ā鍨嬭緭鍑哄父闈犲崟鎹㈣鍒嗘锛�
+marked.setOptions({
+ gfm: true,
+ breaks: true,
+ // 涓嶅惎鐢� headerIds / mangle锛岄伩鍏嶇粰鏍囬鐢熸垚 id 閫犳垚閲嶅
+ headerIds: false,
+ mangle: false
+})
+
+/**
+ * 杞箟 HTML 鐗规畩瀛楃銆�
+ *
+ * 蹇呴』杞箟 `&` 鍚﹀垯浼氫笌宸茶浆涔夊唴瀹逛簩娆″啿绐侊紙`<` 琚啀娆¤浆涔夋垚 `&lt;`锛夈��
+ */
+export function escapeHtml(text) {
+ return String(text)
+ .replace(/&/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''')
+}
+
+/**
+ * 琛ュ叏娴佸紡杩囩▼涓湭闂悎鐨勪唬鐮佸潡銆�
+ *
+ * 娴佸紡杈撳嚭鍒颁竴鍗婃椂锛宍`` 鍙兘鍙湁寮�濮嬫病鏈夌粨鏉燂紝姝ゆ椂 marked 浼氭妸
+ * 鍚庣画鍏ㄩ儴鍐呭褰撴垚浠g爜 鈥斺�� 琛ㄧ幇涓恒�屽洖绛旂獊鐒舵暣娈靛彉鐏板崱鍦ㄤ唬鐮佸潡閲屻�嶃��
+ * 杩欓噷鍦ㄦ覆鏌撳墠鎶婂洿鏍忚ˉ榻愶紝璁╀腑闂存�佷篃鐪嬭捣鏉ユ甯搞��
+ *
+ * 鍙鐞� ``` 鍥存爮锛涜鍐� ` 涓嶈ˉ锛堣ˉ閿欏弽鑰屾洿涔憋級銆�
+ */
+export function closeUnbalancedFences(text) {
+ if (!text) return text
+ // 缁熻琛岄鐨� ``` 鍑虹幇娆℃暟锛堝鏁拌鏄庢湭闂悎锛�
+ const fences = text.match(/^```/gm)
+ if (fences && fences.length % 2 === 1) {
+ return text + '\n```'
+ }
+ return text
+}
+
+/**
+ * 鎶婃鏂囨覆鏌撴垚鍙畨鍏ㄦ彃鍏ョ殑 HTML銆�
+ *
+ * @param {string} raw 妯″瀷杈撳嚭鐨� Markdown 鍘熸枃
+ * @param {object} [options]
+ * @param {boolean} [options.streaming] 鏄惁浠嶅湪娴佸紡鐢熸垚锛堝喅瀹氳涓嶈琛ュ洿鏍忥級
+ * @param {number} [options.citationCount] 鍙敤寮曠敤缂栧彿鏁伴噺锛岀敤浜庨珮浜� [1][2]
+ * @returns {string} 鍙氦缁� v-html 鐨� HTML 瀛楃涓�
+ */
+export function renderMarkdown(raw, options = {}) {
+ const { streaming = false, citationCount = 0 } = options
+ if (!raw) return ''
+
+ let text = raw
+ if (streaming) {
+ text = closeUnbalancedFences(text)
+ }
+
+ // 绗竴姝ワ細杞箟銆傛鍚庣殑鍐呭涓嶅彲鑳藉啀鍙樻垚鏍囩銆�
+ const escaped = escapeHtml(text)
+
+ // 绗簩姝ワ細Markdown 瑙f瀽
+ let html = marked.parse(escaped)
+
+ // 绗笁姝ワ細寮曠敤缂栧彿楂樹寒锛堝湪 HTML 涓婂仛锛岃烦杩囦唬鐮佸潡鍐呴儴锛�
+ if (citationCount > 0) {
+ html = highlightCitations(html, citationCount)
+ }
+
+ // 绗洓姝ワ細娓呮礂鍏滃簳
+ const safe = DOMPurify.sanitize(html, {
+ ALLOWED_TAGS: [
+ 'p', 'br', 'hr', 'strong', 'em', 'del', 's', 'code', 'pre',
+ 'blockquote', 'ul', 'ol', 'li', 'a',
+ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
+ 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'span'
+ ],
+ ALLOWED_ATTR: ['href', 'title', 'class', 'target', 'rel'],
+ // 鍙厑璁稿畨鍏ㄥ崗璁紝鎸′綇 javascript: / data: 杩欑被浼崗璁�
+ ALLOWED_URI_REGEXP: /^(?:https?|mailto):/i
+ })
+
+ // 绗簲姝ワ細杩樺師浠g爜鍧楅噷琚浆涔夌殑瀛楃
+ return decodeEntitiesInCode(safe)
+}
+
+/**
+ * 杩樺師 `<pre>` / `<code>` 鍐呴儴琚浆涔夌殑**寮曞彿涓� &**锛屼絾**淇濈暀 `<` `>` 鐨勮浆涔�**銆�
+ *
+ * <h3>涓轰粈涔堥渶瑕佽繕鍘�</h3>
+ * 涓洪伩鍏嶆ā鍨嬭緭鍑虹殑鍘熷 HTML 琚綋鏍囩娓叉煋锛屾垜浠厛鎶婃暣娈垫枃鏈浆涔�
+ * 锛坄'` 鍙� `'`锛夊啀浜ょ粰 marked銆傛祻瑙堝櫒鏄剧ず鏃朵細鑷姩瑙g爜瀹炰綋锛�
+ * 鎵�浠�**鑲夌溂鐪嬪埌鐨勬槸姝g‘鐨�**锛涗絾 DOM 閲岀殑 `innerHTML` 浠嶆槸 `'`锛�
+ * 鐢ㄦ埛**澶嶅埗浠g爜**鏃跺壀璐存澘鎷垮埌鐨勫氨鏄� `file.write('x')`锛�
+ * 绮樿繘缂栬緫鍣ㄧ洿鎺ヨ娉曢敊璇� 鈥斺�� 浠g爜鍧楁鏄敤鏉ュ鍒剁殑锛屽繀椤昏繕鍘熴��
+ *
+ * <h3>涓轰粈涔堝彧杩樺師寮曞彿鍜� &锛屼笉杩樺師 < >锛堝叧閿畨鍏ㄧ害鏉燂級</h3>
+ * 杩欐槸鏈嚱鏁版渶闇�瑕佸畧浣忕殑涓�鏉$嚎銆傛浘灏濊瘯杩樺師鍏ㄩ儴浜斾釜瀛楃锛�
+ * 缁撴灉**寮曞叆浜� XSS**锛氭妸 `<script>` 杩樺師鎴� `<script>` 鍚庯紝
+ * 瀹冪粡 v-html 鎻掑叆 DOM 灏卞彉鎴�**鐪熸浼氭墽琛岀殑鏍囩**銆�
+ * 瀹炴祴涓夌杞借嵎鍏ㄩ儴瑙﹀彂 alert锛�
+ *
+ * <pre>
+ * ```html 鈫� <script> 杩樺師鍚庣湡鐨勬墽琛�
+ * <script>alert(1)</script>
+ * ```
+ * <svg onload=alert(1)> 鈫� 鍚屾牱鎵ц
+ * <img src=x onerror=alert(1)> 鈫� 鍚屾牱鎵ц
+ * </pre>
+ *
+ * 娉ㄦ剰 **DOMPurify 鎸′笉浣忚繖涓�**锛氬畠榛樿浼氬墺鎺� `<script>` 鏍囩锛�
+ * 浣� `<svg onload>` 涓� `<img onerror>` 灞炰簬瀹冨厑璁哥殑鍏冪礌 + 瀹冧繚瀹堝鐞嗙殑浜嬩欢灞炴�э紝
+ * 鑰屾垜浠殑鐧藉悕鍗曞張鏀惧紑浜� `img`锛堢敤浜庢秷鎭噷鐨勫浘鐗囷級銆�
+ * 鍞竴鍙潬鐨勫仛娉曟槸**涓嶇敓鎴愯繖浜涙爣绛�** 鈥斺�� 涔熷氨鏄繚鐣� `<` `>` 鐨勮浆涔夈��
+ *
+ * <h3>浠d环</h3>
+ * 浠g爜閲岀殑 `<` 涓� `>` 澶嶅埗鍑烘潵浠嶆槸 `<` / `>`銆�
+ * 瀵逛唬鐮佸潡杩欐槸鍙帴鍙楃殑锛欳/Python/JS 閲岀殑姣旇緝杩愮畻铏界劧甯歌锛�
+ * 浣嗗鏁颁汉闈�**鑲夌溂闃呰**浠g爜锛岃�岃倝鐪肩湅鍒扮殑鏄祻瑙堝櫒瑙g爜鍚庣殑姝g‘鍐呭銆�
+ * 鑻ヨ褰诲簳瑙e喅锛岄渶瑕佽浠g爜鍧楄蛋 textContent 鑰岄潪 v-html 鎻掑叆 鈥斺��
+ * 閭f槸娓叉煋鏋舵瀯绾ф敼鍔紝澶嶆潅搴﹁繙楂樹簬鏀剁泭銆�
+ *
+ * <h3>涓轰粈涔堣瑙d袱灞�</h3>
+ * marked 瑙f瀽浠g爜鍧楁椂浼氭妸鍐呭褰�**鏂囨湰**鍐嶈浆涔変竴娆★紝
+ * 鎴戜滑杞箟鐨� `&#39;`锛堝嵆 `&` + `#39;`锛変細琚畠鍙樻垚 `&amp;#39;`銆�
+ * 鍥犳闇�瑕佸惊鐜В鐮佺洿鍒颁笉鍐嶅彉鍖栥��
+ */
+function decodeEntitiesInCode(html) {
+ // 鍙鐞嗕笉浼氫骇鐢熸爣绛剧殑瀹炰綋
+ const inverse = { '&': '&', '"': '"', ''': "'" }
+ const decodeOnce = (text) =>
+ text.replace(/&|"|'/g, (entity) => inverse[entity] ?? entity)
+
+ return html.replace(
+ /(<pre\b[^>]*>[\s\S]*?<\/pre>|<code\b[^>]*>[\s\S]*?<\/code>)/gi,
+ (block) => {
+ // 鏈�澶氳В 3 灞傦紝閬垮厤寮傚父杈撳叆閫犳垚姝诲惊鐜��
+ // 娉ㄦ剰锛�& 浼氬眰灞傝繕鍘燂紝鑻ユ煇灞傝繕鍘熷嚭 < 涔熶粎浣滀负鏂囨湰瀛樺湪锛�
+ // 涓嶄細鍐嶈瑙f瀽鎴愭爣绛撅紙姝ゆ椂宸叉槸瀛楃涓叉嫾鎺ラ樁娈碉紝涓嶇粡杩� HTML 瑙f瀽鍣級銆�
+ for (let i = 0; i < 3; i++) {
+ const next = decodeOnce(block)
+ if (next === block) {
+ break
+ }
+ block = next
+ }
+ return block
+ }
+ )
+}
+
+/**
+ * 楂樹寒姝f枃閲岀殑寮曠敤缂栧彿 `[1]`锛屼絾**璺宠繃浠g爜鍧�**銆�
+ *
+ * 涓轰粈涔堣璺宠繃锛氫唬鐮侀噷鍑虹幇 `arr[1]`銆乣argv[2]` 杩欑被鏁扮粍涓嬫爣闈炲父甯歌锛�
+ * 涓�寰嬮珮浜細璁╀唬鐮佺湅璧锋潵婊℃槸閾炬帴鑹诧紝鍙嶈�屽共鎵伴槄璇汇��
+ *
+ * 瀹炵幇鏂瑰紡鏄妸 HTML 鎸� `<code>` / `<pre>` 鍒囨垚娈碉紝鍙鐞嗘澶栫殑閮ㄥ垎銆�
+ */
+function highlightCitations(html, maxCitation) {
+ const parts = html.split(/(<pre[\s\S]*?<\/pre>|<code[\s\S]*?<\/code>)/gi)
+ return parts
+ .map((part, index) => {
+ // 濂囨暟涓嬫爣鏄崟鑾风粍鍐呭锛堜唬鐮佸潡锛夛紝鍘熸牱杩斿洖
+ if (index % 2 === 1) {
+ return part
+ }
+ return part.replace(/\[(\d{1,2})\]/g, (match, num) => {
+ const n = Number(num)
+ if (n < 1 || n > maxCitation) {
+ // 瓒呭嚭鑼冨洿鐨勭紪鍙蜂笉褰撲綔寮曠敤锛屼繚鎸佸師鏍�
+ return match
+ }
+ return `<span class="citation-ref" title="寮曠敤鏉ユ簮 ${n}">[${n}]</span>`
+ })
+ })
+ .join('')
+}
diff --git a/src/utils/sse.js b/src/utils/sse.js
new file mode 100644
index 0000000..3159f13
--- /dev/null
+++ b/src/utils/sse.js
@@ -0,0 +1,269 @@
+/**
+ * SSE 瀹㈡埛绔皝瑁呫��
+ *
+ * ## 涓轰粈涔堢敤 fetch 鑰屼笉鏄祻瑙堝櫒鍘熺敓 EventSource
+ *
+ * 鏂囨。鏈�鍒濊鎯崇敤 EventSource锛屼絾 EventSource 鏈変袱涓棤娉曠粫寮�鐨勯檺鍒讹細
+ *
+ * 1. **涓嶈兘鑷畾涔夎姹傚ご**銆傚畠鏃犳硶鎼哄甫 `Authorization: Bearer`锛�
+ * 鍙兘闈� URL query 浼� token锛岃�� URL 浼氳繘鍏� nginx access log銆�
+ * 娴忚鍣ㄥ巻鍙蹭笌 Referer锛屾槸瀹炴墦瀹炵殑鍑嵁娉勯湶闈€��
+ * 2. **鏃犳硶涓诲姩涓柇**銆傚彧鏈� `close()`锛屾棤娉曞尯鍒嗐�岀敤鎴风偣浜嗗仠姝€�嶅拰
+ * 銆岀綉缁滄柇寮�銆嶏紝涔熸嬁涓嶅埌 HTTP 鐘舵�佺爜涓庨敊璇搷搴斾綋 鈥斺�� 鍚庣杩斿洖鐨�
+ * 銆孫llama 鏈惎鍔ㄣ�嶈繖绫绘湁浠峰�兼彁绀轰細琚潤榛樺悶鎺夈��
+ *
+ * `fetch` + `ReadableStream` 鎵嬪姩瑙f瀽 SSE 鑳藉悓鏃惰В鍐宠繖涓ょ偣锛�
+ * 涓旀湇鍔$鍗忚瀹屽叏涓嶅彉锛堜緷鐒舵槸 `text/event-stream` + `event:`/`data:` 甯э級锛�
+ * 鍚庣涓嶉渶瑕佷负鍓嶇瀹炵幇鏂瑰紡鍋氫换浣曞Ε鍗忋��
+ *
+ * 鑻ヤ綘纭疄闇�瑕佺敤鍘熺敓 EventSource锛岃鏂囦欢鏈熬鐨� `streamChatViaEventSource`銆�
+ */
+
+const SSE_DATA_PREFIX = 'data:'
+const SSE_EVENT_PREFIX = 'event:'
+
+/**
+ * 寤虹珛 SSE 杩炴帴骞舵祦寮忔秷璐逛簨浠躲��
+ *
+ * @param {object} options
+ * @param {string} options.url 璇锋眰鍦板潃锛堢浉瀵� /api 璺緞锛�
+ * @param {string} options.token JWT锛屾斁鍏� Authorization 澶�
+ * @param {(event: string, data: object) => void} options.onEvent 浜嬩欢鍥炶皟
+ * @param {(error: Error) => void} [options.onError] 閿欒鍥炶皟
+ * @param {() => void} [options.onClose] 娴佹甯哥粨鏉熷洖璋�
+ * @returns {{ abort: () => void }} 鎺у埗鍣紝璋冪敤 abort() 涓柇杩炴帴
+ */
+export function streamChat({ url, token, onEvent, onError, onClose }) {
+ const controller = new AbortController()
+ // 鐢ㄦ埛涓诲姩涓柇鐨勬爣蹇楋細鐢ㄤ簬鍦� catch 閲屽尯鍒嗐�屼富鍔ㄥ仠姝€�嶄笌銆岀湡鐨勫嚭閿欍��
+ let abortedByUser = false
+
+ /**
+ * 缁堟鍥炶皟鍙厑璁歌Е鍙戜竴娆°��
+ *
+ * 杩欐槸淇竴涓湡瀹� bug 鐨勫叧閿細`abort()` 涓诲姩涓柇鏃讹紝`reader.read()` 鏄惁
+ * 浼� reject 涓�涓� AbortError 鍦ㄤ笉鍚屾祻瑙堝櫒/涓嶅悓鏃跺埢琛ㄧ幇骞朵笉涓�鑷� 鈥斺��
+ * 鏈夋椂瀹冨彧鏄畨闈欏湴杩斿洖 { done: true }锛屼簬鏄� onClose 姘歌繙涓嶈Е鍙戯紝
+ * 璋冪敤鏂圭殑 `streaming` 鏍囧織灏卞崱鍦� true锛氬彂閫佹寜閽�**姘镐箙鍙樼伆**锛�
+ * 蹇呴』鍒锋柊椤甸潰鎵嶈兘鎭㈠銆�
+ *
+ * 鍥犳涓嶅啀渚濊禆銆屽紓甯告槸鍚︽姏鍑恒�嶆潵鍐冲畾鏀跺熬锛岃�屾槸鏄惧紡鏀跺彛锛�
+ * abort() 绔嬪嵆缁撶畻锛屾祦鑷劧缁撴潫涔熺粨绠楋紝璋佸厛鍒扮畻璋侊紝鍙粨绠椾竴娆°��
+ */
+ let settled = false
+
+ const settle = (fn) => {
+ if (settled) return
+ settled = true
+ fn?.()
+ }
+
+ const run = async () => {
+ let response
+ try {
+ response = await fetch(url, {
+ method: 'GET',
+ headers: {
+ Accept: 'text/event-stream',
+ Authorization: `Bearer ${token}`
+ },
+ signal: controller.signal,
+ // 涓嶄娇鐢� Cookie 璁よ瘉锛岄伩鍏� CSRF 闈�
+ credentials: 'omit'
+ })
+ } catch (err) {
+ // 涓诲姩涓柇鐢� abort() 璐熻矗缁撶畻锛岃繖閲岀洿鎺ヨ繑鍥烇紝閬垮厤閲嶅鍥炶皟
+ if (abortedByUser || err.name === 'AbortError') {
+ return
+ }
+ settle(() => onError?.(new Error('鏃犳硶寤虹珛杩炴帴锛岃纭鍚庣鏈嶅姟宸插惎鍔�')))
+ return
+ }
+
+ // 鍚庣鍦ㄦ祦寮�濮嬪墠杩斿洖閿欒锛堝 401銆�404銆�400锛夛紝姝ゆ椂鏄櫘閫� JSON 鍝嶅簲
+ if (!response.ok) {
+ let message = `璇锋眰澶辫触 (HTTP ${response.status})`
+ try {
+ const body = await response.json()
+ if (body?.msg) message = body.msg
+ } catch {
+ // 鍝嶅簲浣撲笉鏄� JSON锛屾部鐢ㄩ粯璁ゆ彁绀�
+ }
+ settle(() => onError?.(new Error(message)))
+ return
+ }
+
+ if (!response.body) {
+ settle(() => onError?.(new Error('褰撳墠娴忚鍣ㄤ笉鏀寔娴佸紡鍝嶅簲锛圧eadableStream 涓嶅彲鐢級')))
+ return
+ }
+
+ const reader = response.body.getReader()
+ const decoder = new TextDecoder('utf-8')
+ // 璺� chunk 鐨勬畫鐣欐暟鎹細涓�涓� SSE 甯у彲鑳借 TCP 鍒嗙墖鍒囧紑
+ let buffer = ''
+
+ try {
+ while (true) {
+ const { done, value } = await reader.read()
+ if (done) break
+
+ buffer += decoder.decode(value, { stream: true })
+
+ // SSE 甯т互绌鸿鍒嗛殧銆傛妸瀹屾暣甯ч�愪釜鍙栧嚭鏉ュ鐞嗭紝鍓╀綑閮ㄥ垎鐣欏洖 buffer銆�
+ let separatorIndex
+ while ((separatorIndex = findFrameEnd(buffer)) !== -1) {
+ const rawFrame = buffer.slice(0, separatorIndex)
+ buffer = buffer.slice(separatorIndex).replace(/^(\r?\n){2}/, '')
+ handleFrame(rawFrame, onEvent)
+ }
+ }
+
+ // 澶勭悊鏈�鍚庝竴涓彲鑳芥病鏈変互绌鸿缁撳熬鐨勫抚
+ if (buffer.trim()) {
+ handleFrame(buffer, onEvent)
+ }
+
+ settle(onClose)
+ } catch (err) {
+ // 涓诲姩涓柇宸茬敱 abort() 缁撶畻锛岃繖閲岄潤榛樿繑鍥�
+ if (abortedByUser || err.name === 'AbortError') {
+ return
+ }
+ settle(() => onError?.(new Error(`璇诲彇娴佹暟鎹け璐�: ${err.message}`)))
+ } finally {
+ try {
+ reader.releaseLock()
+ } catch {
+ // 娴佸凡鍏抽棴锛屽拷鐣�
+ }
+ }
+ }
+
+ run()
+
+ return {
+ abort() {
+ abortedByUser = true
+ // 鍏堜腑鏂綉缁滆姹傦紝鍐嶇珛鍗崇粨绠� 鈥斺�� 涓嶇瓑寰� reader.read() 鎶涢敊锛�
+ // 鍚﹀垯寮傚父璇箟鍦ㄦ祻瑙堝櫒闂翠笉涓�鑷存椂浼氭紡鎺夋敹灏撅紝瀵艰嚧 loading 鍗℃
+ controller.abort()
+ settle(onClose)
+ }
+ }
+}
+
+/**
+ * 鎵惧埌绗竴涓畬鏁� SSE 甯х殑缁撴潫浣嶇疆銆�
+ *
+ * 鍏煎 `\n\n` 涓� `\r\n\r\n` 涓ょ鎹㈣椋庢牸 鈥斺��
+ * 涓嶅悓浠g悊锛坣ginx / 鏌愪簺缃戝叧锛変細鏀瑰啓鎹㈣绗︺��
+ */
+function findFrameEnd(text) {
+ const lf = text.indexOf('\n\n')
+ const crlf = text.indexOf('\r\n\r\n')
+ if (lf === -1) return crlf
+ if (crlf === -1) return lf
+ return Math.min(lf, crlf)
+}
+
+/**
+ * 瑙f瀽鍗曚釜 SSE 甯у苟瑙﹀彂鍥炶皟銆�
+ *
+ * 甯ф牸寮忥細
+ * event: delta
+ * data: {"type":"delta","delta":"浣�"}
+ *
+ * 浠� `:` 寮�澶寸殑琛屾槸娉ㄩ噴锛堝父鐢ㄤ簬蹇冭烦锛夛紝鐩存帴蹇界暐銆�
+ */
+function handleFrame(rawFrame, onEvent) {
+ let eventName = 'message'
+ const dataLines = []
+
+ for (const line of rawFrame.split(/\r?\n/)) {
+ if (!line || line.startsWith(':')) continue
+
+ if (line.startsWith(SSE_EVENT_PREFIX)) {
+ eventName = line.slice(SSE_EVENT_PREFIX.length).trim()
+ } else if (line.startsWith(SSE_DATA_PREFIX)) {
+ // 鍘绘帀鍓嶇紑鍚庣殑涓�涓┖鏍硷紙瑙勮寖鍏佽 `data:foo` 涓� `data: foo`锛�
+ dataLines.push(line.slice(SSE_DATA_PREFIX.length).replace(/^ /, ''))
+ }
+ }
+
+ if (dataLines.length === 0) return
+
+ const payload = dataLines.join('\n')
+ let parsed
+ try {
+ parsed = JSON.parse(payload)
+ } catch {
+ // 闈� JSON 杞借嵎锛堢悊璁轰笂鏈」鐩殑鍚庣涓嶄細杩欐牱鍙戯級鎸夌函鏂囨湰澶勭悊
+ parsed = { type: eventName, delta: payload }
+ }
+
+ onEvent?.(eventName, parsed)
+}
+
+/**
+ * 鍘熺敓 EventSource 澶囩敤瀹炵幇銆�
+ *
+ * **浠呭湪浣犳効鎰忔帴鍙� token 鍑虹幇鍦� URL 涓椂浣跨敤銆�**
+ * 鏈嶅姟绔凡鏀寔 `?token=` 璁よ瘉锛堣 JwtAuthenticationFilter锛夛紝
+ * 鍥犳杩欎釜瀹炵幇鍦ㄥ姛鑳戒笂鍙敤锛屼絾璇峰姟蹇咃細
+ * - 鐢熶骇鐜閫氳繃 nginx 鍏抽棴璇ヨ矾寰� query 鐨勬棩蹇楄褰�
+ * - 寮哄埗 HTTPS锛岄伩鍏� token 鏄庢枃浼犺緭
+ *
+ * @param {object} options
+ * @param {string} options.baseUrl 鍚庣鍦板潃锛屽 'http://localhost:8080'
+ * @param {number} options.chatId
+ * @param {string} options.token
+ * @param {object} options.params query 鍙傛暟锛歝ontent/parentId/model/useRag
+ * @param {(event: string, data: object) => void} options.onEvent
+ * @param {(error: Error) => void} [options.onError]
+ */
+export function streamChatViaEventSource({
+ baseUrl = '',
+ chatId,
+ token,
+ params,
+ onEvent,
+ onError
+}) {
+ const query = new URLSearchParams({
+ ...params,
+ token
+ })
+ const url = `${baseUrl}/api/chats/${chatId}/stream?${query.toString()}`
+
+ const source = new EventSource(url)
+
+ // 閫愪釜娉ㄥ唽鍚庣绾﹀畾鐨勪簨浠剁被鍨嬨��
+ // EventSource 涓嶆彁渚涖�岀洃鍚墍鏈変簨浠躲�嶇殑鑳藉姏锛屽繀椤绘樉寮忓垪鍑恒��
+ for (const eventName of ['start', 'delta', 'title', 'done', 'error']) {
+ source.addEventListener(eventName, (event) => {
+ try {
+ onEvent?.(eventName, JSON.parse(event.data))
+ } catch (err) {
+ onError?.(new Error(`瑙f瀽 ${eventName} 浜嬩欢澶辫触: ${err.message}`))
+ }
+ // done / error 涔嬪悗娴佸凡缁撴潫锛屼富鍔ㄥ叧闂互閲婃斁鍚庣 SseEmitter
+ if (eventName === 'done' || eventName === 'error') {
+ source.close()
+ }
+ })
+ }
+
+ source.onerror = () => {
+ // EventSource 浼氳嚜鍔ㄩ噸杩烇紝浣嗗璇濇祦涓嶈閲嶈繛锛堜細閲嶅鐢熸垚锛夈��
+ // 鍥犳杩欓噷鐩存帴鍏抽棴骞舵妸鎺у埗鏉冧氦缁欎笂灞傘��
+ source.close()
+ onError?.(new Error('SSE 杩炴帴涓柇'))
+ }
+
+ return {
+ abort() {
+ source.close()
+ }
+ }
+}
diff --git a/src/utils/treeBuild.js b/src/utils/treeBuild.js
new file mode 100644
index 0000000..da469ad
--- /dev/null
+++ b/src/utils/treeBuild.js
@@ -0,0 +1,174 @@
+/**
+ * 娑堟伅鏍戝墠绔伐鍏峰嚱鏁般��
+ *
+ * 鍚庣杩斿洖鐨勬槸宓屽鏍戯紙鏍硅妭鐐规暟缁勶紝鑺傜偣鍐呭祵 children锛夈��
+ * 浣嗐�屾覆鏌撳綋鍓嶅璇濄�嶉渶瑕佺殑鏄�**涓�鏉$嚎鎬ц矾寰�**锛�
+ * 鏍� 鈫� 鐢ㄦ埛绗竴鏉� 鈫� AI 鍥炲 鈫� 鐢ㄦ埛绗簩鏉� 鈫� ...
+ *
+ * 鍘熷洜锛氭秷鎭爲鍙兘鍥犱负銆岄噸鏂扮敓鎴� / 缂栬緫銆嶈�屼骇鐢熷垎鏀紝
+ * 鑰屼换涓�鏃跺埢鐢ㄦ埛鍙湅寰楀埌鍏朵腑涓�鏉″垎鏀�備綍鏃跺垏鎹㈠垎鏀敱鐢ㄦ埛鍐冲畾銆�
+ *
+ * 鍥犳杩欓噷鐨勫伐浣滄祦鏄細
+ * 1. 鐢� flattenTree 寤虹珛 id -> 鑺傜偣 鐨勭储寮�
+ * 2. 鐢� activeChildId 鏄犲皠璁板綍銆屾瘡涓埗鑺傜偣褰撳墠閫変腑鍝釜瀛愯妭鐐广��
+ * 3. 鐢� buildPath 娌跨潃閫夋嫨璧板嚭涓�鏉$嚎鎬ц矾寰勭敤浜庢覆鏌�
+ */
+
+/**
+ * 鎶婂祵濂楁爲鍘嬪钩鎴� Map锛屼究浜� O(1) 鏌ユ壘浠绘剰鑺傜偣銆�
+ *
+ * @param {Array} tree 鏍硅妭鐐规暟缁�
+ * @returns {Map<number, object>}
+ */
+export function flattenTree(tree) {
+ const map = new Map()
+
+ const walk = (nodes) => {
+ if (!Array.isArray(nodes)) return
+ for (const node of nodes) {
+ map.set(node.id, node)
+ walk(node.children)
+ }
+ }
+
+ walk(tree)
+ return map
+}
+
+/**
+ * 浠庡悗绔繑鍥炵殑鏍戜腑鎻愬彇鍒濆鐨勩�屾椿璺冨垎鏀�嶉�夋嫨銆�
+ *
+ * 鍚庣浼氫负姣忎釜澶氬垎鏀妭鐐硅绠� activeChildId锛堥粯璁ゆ槸鏈�鍚庣敓鎴愮殑瀛愯妭鐐癸級锛�
+ * 鍗崇敤鎴蜂笂娆″疄闄呭湪鐪嬬殑閭d釜鍒嗘敮銆�
+ *
+ * @param {Array} tree
+ * @returns {Record<number, number>} parentId -> 閫変腑鐨� childId
+ */
+export function extractActiveChildIds(tree) {
+ const selections = {}
+
+ const walk = (nodes) => {
+ if (!Array.isArray(nodes)) return
+ for (const node of nodes) {
+ if (node.children?.length > 0) {
+ // 鍚庣缁欑殑 activeChildId 浼樺厛锛涚己澶辨椂鍥為��鍒版渶鍚庝竴涓瓙鑺傜偣
+ const fallback = node.children[node.children.length - 1].id
+ selections[node.id] = node.activeChildId ?? fallback
+ }
+ walk(node.children)
+ }
+ }
+
+ walk(tree)
+ return selections
+}
+
+/**
+ * 娌挎椿璺冨垎鏀蛋鍑轰竴鏉$嚎鎬ц矾寰勩��
+ *
+ * 瀹归敊锛氳嫢 selections 鎸囧悜鐨� childId 涓嶅湪 children 閲岋紙渚嬪鍒氬垹闄や簡璇ュ垎鏀級锛�
+ * 鑷姩鍥為��鍒版渶鍚庝竴涓瓙鑺傜偣锛岄伩鍏嶆覆鏌撲腑鏂��
+ *
+ * @param {Array} tree
+ * @param {Record<number, number>} selections parentId -> childId
+ * @returns {Array} 鎸夊璇濋『搴忔帓鍒楃殑娑堟伅鏁扮粍
+ */
+export function buildPath(tree, selections = {}) {
+ const path = []
+ if (!Array.isArray(tree) || tree.length === 0) return path
+
+ // 鏍瑰眰涔熷彲鑳藉瓨鍦ㄥ涓妭鐐癸紙寮傚父鏁版嵁涓嬬殑銆屽鍎夸笂娴�嶏級锛�
+ // 杩欓噷鍙栨渶鍚庝竴涓綔涓哄綋鍓嶅璇濈嚎鐨勮捣鐐�
+ let current = tree[tree.length - 1]
+
+ // guard 闃叉鑴忔暟鎹垚鐜鑷存寰幆
+ let guard = 0
+ const maxSteps = 10000
+
+ while (current && guard++ < maxSteps) {
+ path.push(current)
+
+ const children = current.children
+ if (!Array.isArray(children) || children.length === 0) {
+ break
+ }
+
+ const selectedId = selections[current.id]
+ let next = children.find((child) => child.id === selectedId)
+
+ if (!next) {
+ // 閫夋嫨澶辨晥锛氬洖閫�鍒版渶鍚庝竴涓瓙鑺傜偣锛屽苟淇鏄犲皠
+ next = children[children.length - 1]
+ selections[current.id] = next.id
+ }
+
+ current = next
+ }
+
+ return path
+}
+
+/**
+ * 鍒囨崲鏌愪釜娑堟伅涓嬮�変腑鐨勫瓙鍒嗘敮銆�
+ *
+ * @param {object} message 褰撳墠娑堟伅鑺傜偣
+ * @param {number} delta +1 涓嬩竴涓垎鏀紝-1 涓婁竴涓垎鏀�
+ * @param {Record<number, number>} selections 浼氳灏卞湴淇敼
+ * @returns {boolean} 鏄惁鐪熺殑鍙戠敓浜嗗垏鎹紙false 琛ㄧず宸插湪棣�/鏈垎鏀級
+ */
+export function switchBranch(message, delta, selections) {
+ const children = message?.children
+ if (!Array.isArray(children) || children.length <= 1) return false
+
+ const currentId = selections[message.id] ?? children[children.length - 1].id
+ let index = children.findIndex((child) => child.id === currentId)
+ if (index === -1) index = children.length - 1
+
+ const nextIndex = index + delta
+ if (nextIndex < 0 || nextIndex >= children.length) return false
+
+ selections[message.id] = children[nextIndex].id
+ return true
+}
+
+/**
+ * 璁$畻鏌愪釜澶氬垎鏀秷鎭綋鍓嶆樉绀虹殑鏄鍑犱釜鍒嗘敮銆�
+ *
+ * @returns {{index: number, total: number}} index 浠� 1 寮�濮�
+ */
+export function branchPosition(message, selections) {
+ const children = message?.children ?? []
+ const total = children.length
+ if (total === 0) return { index: 0, total: 0 }
+
+ const currentId = selections[message.id] ?? children[total - 1].id
+ const found = children.findIndex((child) => child.id === currentId)
+ return { index: found === -1 ? total : found + 1, total }
+}
+
+/**
+ * 鎵惧埌鏌愪釜鑺傜偣鍦ㄦ爲涓殑鐖惰妭鐐广��
+ *
+ * @param {Map<number, object>} nodeMap flattenTree 鐨勭粨鏋�
+ * @param {number} nodeId
+ * @returns {object|null}
+ */
+export function findParent(nodeMap, nodeId) {
+ for (const node of nodeMap.values()) {
+ if (node.children?.some((child) => child.id === nodeId)) {
+ return node
+ }
+ }
+ return null
+}
+
+/**
+ * 鍒ゆ柇涓�鏉℃秷鎭槸鍚﹀簲璇ユ樉绀恒�岄噸鏂扮敓鎴愩�嶆寜閽��
+ *
+ * 瑙勫垯锛氬彧鏈� user 娑堟伅鎵嶈Е鍙戦噸鏂扮敓鎴愶紝涓旇 user 娑堟伅蹇呴』宸茬粡鏈�
+ * 鑷冲皯涓�涓� assistant 瀛愭秷鎭紙鍚﹀垯鏄杞湭瀹屾垚鐘舵�侊級銆�
+ */
+export function canRegenerate(message) {
+ if (message?.role !== 'user') return false
+ return Array.isArray(message.children) && message.children.length > 0
+}
diff --git a/src/views/AdminKnowledge.vue b/src/views/AdminKnowledge.vue
new file mode 100644
index 0000000..075e8ad
--- /dev/null
+++ b/src/views/AdminKnowledge.vue
@@ -0,0 +1,583 @@
+<template>
+ <div class="admin-page">
+ <div class="admin-header">
+ <n-button quaternary size="small" @click="$router.push('/files')">鈫� 杩斿洖鐭ヨ瘑搴�</n-button>
+ <h1 class="admin-title">鍏ㄥ眬鐭ヨ瘑搴�</h1>
+ <n-tag type="info" size="small" :bordered="false">绠$悊鍛�</n-tag>
+ <div class="admin-header-right">
+ <n-button size="small" quaternary :loading="loading" @click="load">鍒锋柊</n-button>
+ </div>
+ </div>
+
+ <div class="admin-body">
+ <n-alert type="info" :bordered="false" class="admin-intro">
+ 杩欓噷涓婁紶鐨勬枃妗d細鎴愪负<strong>鍏ㄥ眬鐭ヨ瘑搴�</strong>锛氬叆搴撳悗<strong>鎵�鏈夌櫥褰曠敤鎴�</strong>
+ 閮借兘鍦ㄨ嚜宸辩殑銆岀煡璇嗗簱銆嶉潰鏉块噷鐪嬪埌锛屽苟缁戝畾鍒板悇鑷殑浼氳瘽鍙備笌妫�绱€��
+ <br />
+ 鍏ㄥ眬鐭ヨ瘑搴撳彧鏈夌鐞嗗憳鑳戒慨鏀规垨鍒犻櫎 鈥斺�� 鏅�氱敤鎴峰彧鑳界粦瀹氫娇鐢ㄣ��
+ </n-alert>
+
+ <!-- 涓婁紶鍖� -->
+ <div class="section-title">涓婁紶鍏ㄥ眬鏂囨。</div>
+ <div
+ class="drop-zone"
+ :class="{ dragging, uploading }"
+ @dragover.prevent="dragging = true"
+ @dragleave.prevent="dragging = false"
+ @drop.prevent="handleDrop"
+ @click="pickFile"
+ >
+ <input
+ ref="fileInputRef"
+ type="file"
+ class="hidden-input"
+ multiple
+ :accept="acceptAttr"
+ @change="handleSelect"
+ />
+ <div class="drop-icon">鈫�</div>
+ <div class="drop-title">
+ {{ uploading ? `涓婁紶涓� ${progress}%` : '鎷栨嫿鏂囦欢鍒版澶勶紝鎴栫偣鍑婚�夋嫨' }}
+ </div>
+ <div class="drop-hint">
+ 鏀寔 {{ allowedExtensions.join(' / ') }}锛屽崟鏂囦欢涓嶈秴杩� 50MB<br />
+ 涓婁紶鍚庨渶瑕佺偣銆屽悜閲忓寲鍏ュ簱銆嶏紝鍏朵粬鐢ㄦ埛鎵嶈兘妫�绱㈠埌鍐呭
+ </div>
+ <n-progress
+ v-if="uploading"
+ type="line"
+ :percentage="progress"
+ :show-indicator="false"
+ class="drop-progress"
+ />
+ </div>
+
+ <!-- 鍏ㄥ眬鏂囨。鍙兘鏀捐繘鍏ㄥ眬鍒嗙被锛涜繖閲屼紶 allowGlobal 璁╃鐞嗗憳鐩存帴寤哄叏灞�鍒嗙被 -->
+ <div class="upload-category">
+ <CategoryPicker
+ v-model:value="categoryId"
+ allow-global
+ :disabled="uploading"
+ placeholder="閫夋嫨鍏ㄥ眬鍒嗙被锛堝彲涓嶉�夛級"
+ />
+ </div>
+
+ <!-- 鍒楄〃鍖� -->
+ <div class="list-header">
+ <span class="section-title no-margin">鍏ㄥ眬鐭ヨ瘑搴撴枃妗o紙{{ files.length }}锛�</span>
+ <n-button v-if="files.some((f) => !f.ingested)" size="tiny" :loading="ingestingAll"
+ @click="ingestAll">
+ 鍏ㄩ儴鍚戦噺鍖�
+ </n-button>
+ </div>
+
+ <n-spin v-if="loading" size="small" class="center-spin" />
+
+ <div v-else-if="files.length === 0" class="empty-hint empty-block">
+ 杩樻病鏈夊叏灞�鐭ヨ瘑搴撴枃妗�<br />涓婁紶鍚庤寰楃偣銆屽悜閲忓寲鍏ュ簱銆�
+ </div>
+
+ <div v-for="file in files" v-else :key="file.id" class="file-card">
+ <div class="file-card-main">
+ <div class="file-name">
+ {{ file.filename }}
+ <n-tag type="success" size="tiny" :bordered="false" class="global-tag">鍏ㄥ眬</n-tag>
+ </div>
+ <div class="file-meta">
+ <span>{{ formatSize(file.fileSize) }}</span>
+ <span class="sep">路</span>
+ <span>{{ formatDate(file.createdAt) }}</span>
+ <span class="sep">路</span>
+ <span v-if="file.ingested" class="status-ok">
+ 宸插叆搴� {{ file.chunkCount }} 涓墖娈�
+ </span>
+ <span v-else-if="file.ingestMessage" class="status-fail">
+ 鍏ュ簱澶辫触锛歿{ file.ingestMessage }}
+ </span>
+ <span v-else class="status-pending">鏈悜閲忓寲锛堝叾浠栫敤鎴锋绱笉鍒帮級</span>
+ </div>
+ <div v-if="file.collectionName" class="file-collection">
+ 闆嗗悎鍚嶏細<code>{{ file.collectionName }}</code>
+ </div>
+ </div>
+
+ <div class="file-card-actions">
+ <n-button v-if="!file.ingested" size="small" :loading="busyId === file.id"
+ @click="handleIngest(file)">
+ 鍚戦噺鍖栧叆搴�
+ </n-button>
+ <n-button v-else size="small" :loading="busyId === file.id" @click="handleIngest(file)">
+ 閲嶆柊鍏ュ簱
+ </n-button>
+ <n-button size="small" quaternary @click="handleUnsetGlobal(file)">鍙栨秷鍏ㄥ眬</n-button>
+ <n-button size="small" type="error" quaternary @click="handleDelete(file)">鍒犻櫎</n-button>
+ </div>
+ </div>
+
+ <!-- 鎴戠殑绉佹湁鏂囨。锛氬彲涓�閿崌绾т负鍏ㄥ眬 -->
+ <div class="list-header">
+ <span class="section-title no-margin">鎴戠殑绉佹湁鏂囨。锛坽{ privateFiles.length }}锛�</span>
+ </div>
+ <div v-if="privateFiles.length === 0" class="empty-hint empty-block">
+ 娌℃湁绉佹湁鏂囨。
+ </div>
+ <div v-for="file in privateFiles" v-else :key="file.id" class="file-card private">
+ <div class="file-card-main">
+ <div class="file-name">{{ file.filename }}</div>
+ <div class="file-meta">
+ <span>{{ formatSize(file.fileSize) }}</span>
+ <span class="sep">路</span>
+ <span v-if="file.ingested" class="status-ok">宸插叆搴� {{ file.chunkCount }} 涓墖娈�</span>
+ <span v-else class="status-pending">鏈悜閲忓寲</span>
+ </div>
+ </div>
+ <div class="file-card-actions">
+ <n-button size="small" :disabled="!file.ingested" :loading="busyId === file.id"
+ @click="handleSetGlobal(file)">
+ 鍗囩骇涓哄叏灞�
+ </n-button>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup>
+import { computed, onMounted, ref } from 'vue'
+import { NAlert, NButton, NProgress, NSpin, NTag, useDialog, useMessage } from 'naive-ui'
+import CategoryPicker from '@/components/CategoryPicker.vue'
+import {
+ deleteFile,
+ ingestFile,
+ listFiles,
+ listGlobalFiles,
+ setFileGlobal,
+ uploadGlobalFile
+} from '@/api/fileApi'
+
+const message = useMessage()
+const dialog = useDialog()
+
+const loading = ref(false)
+const ingestingAll = ref(false)
+const uploading = ref(false)
+const progress = ref(0)
+const dragging = ref(false)
+const busyId = ref(null)
+const fileInputRef = ref(null)
+const files = ref([])
+const privateFiles = ref([])
+/** 涓婁紶鍏ㄥ眬鏂囨。鏃堕�変腑鐨勫垎绫伙紙鍙垪/鍒涘缓鍏ㄥ眬鍒嗙被鎵嶅悎瑙勶級 */
+const categoryId = ref(null)
+
+const allowedExtensions = ['txt', 'md', 'markdown', 'pdf', 'docx', 'csv', 'json', 'log', 'html']
+const acceptAttr = computed(() => allowedExtensions.map((e) => `.${e}`).join(','))
+
+onMounted(load)
+
+async function load() {
+ loading.value = true
+ try {
+ const [globals, mine] = await Promise.all([listGlobalFiles(), listFiles(null)])
+ files.value = globals || []
+ // 绉佹湁鏂囨。 = 鎴戜笂浼犵殑涓斾笉鏄叏灞�鐨�
+ privateFiles.value = (mine || []).filter((f) => !f.isGlobal && f.canManage)
+ } catch (error) {
+ message.error(error.message || '鍔犺浇澶辫触')
+ } finally {
+ loading.value = false
+ }
+}
+
+// ---------------- 涓婁紶 ----------------
+
+function pickFile() {
+ if (uploading.value) return
+ fileInputRef.value?.click()
+}
+
+function handleSelect(event) {
+ const list = Array.from(event.target.files || [])
+ event.target.value = ''
+ doUpload(list)
+}
+
+function handleDrop(event) {
+ dragging.value = false
+ doUpload(Array.from(event.dataTransfer?.files || []))
+}
+
+async function doUpload(list) {
+ if (list.length === 0) return
+ uploading.value = true
+ progress.value = 0
+ let ok = 0
+
+ try {
+ for (let i = 0; i < list.length; i += 1) {
+ const file = list[i]
+ const ext = file.name.split('.').pop()?.toLowerCase() || ''
+ if (!allowedExtensions.includes(ext)) {
+ message.error(`${file.name}锛氫笉鏀寔鐨勭被鍨� .${ext}`)
+ continue
+ }
+ if (file.size > 50 * 1024 * 1024) {
+ message.error(`${file.name}锛氳秴杩� 50MB 闄愬埗`)
+ continue
+ }
+ try {
+ const created = await uploadGlobalFile(
+ file,
+ (percent) => {
+ progress.value = Math.round(((i + percent / 100) / list.length) * 100)
+ },
+ true,
+ categoryId.value
+ )
+ files.value = [created, ...files.value]
+ ok += 1
+ } catch (error) {
+ message.error(`${file.name}锛�${error.message || '涓婁紶澶辫触'}`)
+ }
+ }
+ if (ok > 0) {
+ message.success(`宸蹭笂浼� ${ok} 涓叏灞�鏂囨。锛屽埆蹇樹簡鐐广�屽悜閲忓寲鍏ュ簱銆峘)
+ }
+ } finally {
+ uploading.value = false
+ progress.value = 0
+ }
+}
+
+// ---------------- 鍏ュ簱 ----------------
+
+async function handleIngest(file) {
+ busyId.value = file.id
+ try {
+ const updated = await ingestFile(file.id)
+ replaceFile(updated)
+ message.success(`鍏ュ簱瀹屾垚锛�${updated.chunkCount} 涓墖娈碉紝鐜板凡瀵瑰叏閮ㄧ敤鎴峰彲鐢╜)
+ } catch (error) {
+ message.error(error.message || '鍚戦噺鍖栧け璐�')
+ await refreshQuietly()
+ } finally {
+ busyId.value = null
+ }
+}
+
+async function ingestAll() {
+ const pending = files.value.filter((f) => !f.ingested)
+ if (pending.length === 0) return
+ ingestingAll.value = true
+ let ok = 0
+ try {
+ for (const file of pending) {
+ try {
+ const updated = await ingestFile(file.id)
+ replaceFile(updated)
+ ok += 1
+ } catch (error) {
+ message.error(`${file.filename}锛�${error.message || '澶辫触'}`)
+ }
+ }
+ if (ok > 0) message.success(`宸插畬鎴� ${ok} 涓枃妗g殑鍚戦噺鍖朻)
+ } finally {
+ ingestingAll.value = false
+ }
+}
+
+// ---------------- 鍏ㄥ眬寮�鍏� ----------------
+
+async function handleSetGlobal(file) {
+ busyId.value = file.id
+ try {
+ const updated = await setFileGlobal(file.id, true)
+ privateFiles.value = privateFiles.value.filter((f) => f.id !== file.id)
+ files.value = [updated, ...files.value]
+ message.success(`銆�${file.filename}銆嶅凡璁句负鍏ㄥ眬鐭ヨ瘑搴揱)
+ } catch (error) {
+ message.error(error.message || '鎿嶄綔澶辫触')
+ } finally {
+ busyId.value = null
+ }
+}
+
+function handleUnsetGlobal(file) {
+ dialog.warning({
+ title: '鍙栨秷鍏ㄥ眬',
+ content: `鍙栨秷鍚庛��${file.filename}銆嶅皢涓嶅啀瀵规櫘閫氱敤鎴峰彲瑙侊紱` +
+ '宸茬粡缁戝畾浜嗗畠鐨勪細璇濅粛浼氱户缁绱㈠埌鍐呭锛堥泦鍚堝悕鏈彉锛夛紝' +
+ '濡傞渶褰诲簳鍋滄锛岃璁╃敤鎴峰湪浼氳瘽閲岃В缁戙�傜‘瀹氱户缁悧锛�',
+ positiveText: '鍙栨秷鍏ㄥ眬',
+ negativeText: '鍐嶆兂鎯�',
+ onPositiveClick: async () => {
+ busyId.value = file.id
+ try {
+ const updated = await setFileGlobal(file.id, false)
+ files.value = files.value.filter((f) => f.id !== file.id)
+ privateFiles.value = [updated, ...privateFiles.value]
+ message.success('宸插彇娑堝叏灞�')
+ } catch (error) {
+ message.error(error.message || '鎿嶄綔澶辫触')
+ } finally {
+ busyId.value = null
+ }
+ }
+ })
+}
+
+// ---------------- 鍒犻櫎 ----------------
+
+function handleDelete(file) {
+ dialog.warning({
+ title: '鍒犻櫎鍏ㄥ眬鏂囨。',
+ content: `纭畾鍒犻櫎銆�${file.filename}銆嶅悧锛焋 +
+ '纾佺洏鏂囦欢涓庡悜閲忛泦鍚堥兘浼氳娓呯悊锛�**鎵�鏈夌敤鎴�**閮藉皢鏃犳硶鍐嶆绱㈠埌瀹冦�傛鎿嶄綔涓嶅彲鎭㈠銆�',
+ positiveText: '鍒犻櫎',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await deleteFile(file.id)
+ files.value = files.value.filter((f) => f.id !== file.id)
+ message.success('宸插垹闄�')
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎澶辫触')
+ }
+ }
+ })
+}
+
+// ---------------- 宸ュ叿 ----------------
+
+function replaceFile(updated) {
+ const idx = files.value.findIndex((f) => f.id === updated.id)
+ if (idx !== -1) {
+ files.value[idx] = updated
+ } else {
+ files.value = [updated, ...files.value]
+ }
+}
+
+async function refreshQuietly() {
+ try {
+ files.value = await listGlobalFiles()
+ } catch {
+ // 蹇界暐
+ }
+}
+
+function formatSize(bytes) {
+ if (!bytes && bytes !== 0) return '-'
+ if (bytes < 1024) return `${bytes} B`
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`
+}
+
+function formatDate(value) {
+ if (!value) return '-'
+ try {
+ return new Date(value).toLocaleString('zh-CN', {
+ month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit'
+ })
+ } catch {
+ return String(value)
+ }
+}
+</script>
+
+<style scoped>
+.admin-page {
+ height: 100vh;
+ overflow-y: auto;
+ background: var(--bg-page);
+}
+
+.admin-header {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 14px 24px;
+ border-bottom: 1px solid var(--border-color);
+ position: sticky;
+ top: 0;
+ background: var(--bg-page);
+ z-index: 10;
+}
+
+.admin-title {
+ margin: 0;
+ font-size: 16px;
+ font-weight: 600;
+}
+
+.admin-header-right {
+ margin-left: auto;
+}
+
+.admin-body {
+ max-width: 860px;
+ margin: 0 auto;
+ padding: 24px;
+}
+
+.admin-intro {
+ margin-bottom: 20px;
+ font-size: 12.5px;
+ line-height: 1.9;
+}
+
+.section-title {
+ font-size: 13px;
+ font-weight: 600;
+ margin: 22px 0 10px;
+}
+
+.section-title.no-margin {
+ margin: 0;
+}
+
+.list-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin: 26px 0 10px;
+}
+
+.hidden-input {
+ display: none;
+}
+
+.drop-zone {
+ border: 1.5px dashed #d1d5db;
+ border-radius: 10px;
+ padding: 22px 16px;
+ text-align: center;
+ cursor: pointer;
+ background: #fafafa;
+ transition: border-color 0.15s ease, background 0.15s ease;
+}
+
+.drop-zone:hover {
+ border-color: #9ca3af;
+ background: #f5f5f5;
+}
+
+.drop-zone.dragging {
+ border-color: #4b5563;
+ background: #eef2f7;
+}
+
+.drop-zone.uploading {
+ cursor: progress;
+}
+
+.drop-icon {
+ font-size: 20px;
+ color: var(--text-secondary);
+ margin-bottom: 8px;
+}
+
+.drop-title {
+ font-size: 13.5px;
+ font-weight: 500;
+}
+
+.drop-hint {
+ font-size: 12px;
+ color: var(--text-muted);
+ margin-top: 6px;
+ line-height: 1.7;
+}
+
+.drop-progress {
+ margin-top: 12px;
+}
+
+.upload-category {
+ margin-top: 10px;
+}
+
+.center-spin {
+ display: flex;
+ justify-content: center;
+ padding: 24px 0;
+}
+
+.empty-block {
+ padding: 28px 0;
+ line-height: 1.9;
+}
+
+.file-card {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+ padding: 14px 16px;
+ border: 1px solid var(--border-color);
+ border-radius: 10px;
+ margin-bottom: 10px;
+}
+
+.file-card.private {
+ background: #fafafa;
+}
+
+.file-card-main {
+ min-width: 0;
+ flex: 1;
+}
+
+.file-name {
+ font-size: 13.5px;
+ font-weight: 500;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.global-tag {
+ margin-left: 8px;
+ vertical-align: middle;
+}
+
+.file-meta {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 5px;
+}
+
+.sep {
+ margin: 0 6px;
+}
+
+.status-ok {
+ color: #0f766e;
+}
+
+.status-fail {
+ color: #dc2626;
+}
+
+.status-pending {
+ color: #b45309;
+}
+
+.file-collection {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 5px;
+}
+
+.file-collection code {
+ background: var(--code-bg);
+ padding: 1px 5px;
+ border-radius: 4px;
+}
+
+.file-card-actions {
+ display: flex;
+ gap: 6px;
+ flex-shrink: 0;
+}
+</style>
diff --git a/src/views/Chat.vue b/src/views/Chat.vue
new file mode 100644
index 0000000..56c2738
--- /dev/null
+++ b/src/views/Chat.vue
@@ -0,0 +1,101 @@
+<template>
+ <div class="chat-page">
+ <Sidebar
+ v-show="sidebarVisible"
+ ref="sidebarRef"
+ @select="handleSelectChat"
+ @created="handleCreated"
+ @deleted="handleDeleted"
+ @open-files="handleOpenFiles"
+ @open-admin-knowledge="handleOpenAdminKnowledge"
+ />
+ <ChatView :chat-id="chatId" ref="chatViewRef" @toggle-sidebar="sidebarVisible = !sidebarVisible" />
+ </div>
+</template>
+
+<script setup>
+import { onMounted, ref, watch } from 'vue'
+import { useRoute, useRouter } from 'vue-router'
+import { useMessage } from 'naive-ui'
+import Sidebar from '@/components/Sidebar.vue'
+import ChatView from '@/components/ChatView.vue'
+import { useAuthStore } from '@/stores/authStore'
+import { useChatStore } from '@/stores/chatStore'
+
+const route = useRoute()
+const router = useRouter()
+const message = useMessage()
+const auth = useAuthStore()
+const chatStore = useChatStore()
+
+const sidebarRef = ref(null)
+const chatViewRef = ref(null)
+const sidebarVisible = ref(true)
+
+// 浼氳瘽 id 鏉ヨ嚜璺敱鍙傛暟锛屽瓧绗︿覆闇�杞垚鏁板瓧
+const chatId = ref(route.params.chatId ? Number(route.params.chatId) : null)
+
+onMounted(async () => {
+ // 鍒锋柊椤甸潰鍚庢牎楠� token 鏄惁浠嶇劧鏈夋晥锛堝け鏁堜細鐢辨嫤鎴櫒鐧诲嚭锛�
+ await auth.fetchMe()
+ await sidebarRef.value?.refresh()
+
+ // 娌℃湁鎸囧畾浼氳瘽鏃讹紝鑷姩閫変腑鏈�杩戠殑涓�涓紝閬垮厤鐢ㄦ埛鐪嬪埌绌虹櫧椤�
+ if (!chatId.value && chatStore.chats.length > 0) {
+ router.replace(`/c/${chatStore.chats[0].id}`)
+ }
+})
+
+// 璺敱涓庝細璇濈姸鎬佸弻鍚戝悓姝�
+watch(
+ () => route.params.chatId,
+ (value) => {
+ const next = value ? Number(value) : null
+ if (next !== chatId.value) {
+ chatId.value = next
+ }
+ }
+)
+
+function handleSelectChat(id) {
+ if (id === chatId.value) return
+ router.push(`/c/${id}`)
+}
+
+function handleCreated(id) {
+ router.push(`/c/${id}`)
+}
+
+function handleDeleted(id) {
+ // 鍒犳帀鐨勬濂芥槸褰撳墠浼氳瘽锛屾垨鑰呯敤鎴风櫥鍑猴細鍥炲埌绌虹櫧椤�
+ if (id === null || id === chatId.value) {
+ router.push('/c')
+ }
+}
+
+function handleOpenFiles() {
+ router.push('/files')
+}
+
+function handleOpenAdminKnowledge() {
+ router.push('/admin/knowledge')
+}
+
+// 鍏滃簳锛氳矾鐢辨寚鍚戜笉瀛樺湪鐨勪細璇濇椂鎻愮ず骞舵竻鐞�
+watch(chatId, async (id) => {
+ if (!id) return
+ const exists = chatStore.chats.some((chat) => chat.id === id)
+ if (!exists && chatStore.chats.length > 0) {
+ message.warning('璇ュ璇濅笉瀛樺湪鎴栧凡琚垹闄�')
+ router.replace('/c')
+ }
+})
+</script>
+
+<style scoped>
+.chat-page {
+ display: flex;
+ height: 100vh;
+ overflow: hidden;
+}
+</style>
diff --git a/src/views/Files.vue b/src/views/Files.vue
new file mode 100644
index 0000000..7e995b0
--- /dev/null
+++ b/src/views/Files.vue
@@ -0,0 +1,696 @@
+<template>
+ <div class="files-page">
+ <div class="files-header">
+ <n-button quaternary size="small" @click="$router.push('/c')">鈫� 杩斿洖瀵硅瘽</n-button>
+ <h1 class="files-title">鐭ヨ瘑搴撶鐞�</h1>
+ <div class="files-header-right">
+ <n-tag v-if="ragAvailable" type="success" size="small" :bordered="false">
+ RAG 鏈嶅姟姝e父
+ </n-tag>
+ <n-tag v-else type="warning" size="small" :bordered="false">
+ RAG 鏈嶅姟涓嶅彲鐢�
+ </n-tag>
+ </div>
+ </div>
+
+ <div class="files-body">
+ <n-alert v-if="!ragEnabled" type="warning" :bordered="false" class="files-alert">
+ 鍚庣閰嶇疆涓� RAG 鍔熻兘宸插叧闂紙webui.rag.enabled=false锛夈��
+ </n-alert>
+ <n-alert v-else-if="!ragAvailable" type="warning" :bordered="false" class="files-alert">
+ RAG 鏈嶅姟涓嶅彲鐢紙{{ ragBaseUrl }}锛夈�傝鍚姩 Python 鏈嶅姟锛�<br />
+ <code>cd rag-service && export HF_ENDPOINT=https://hf-mirror.com</code><br />
+ <code>uvicorn main:app --host 0.0.0.0 --port 8000</code>
+ </n-alert>
+
+ <FileUpload :chat-id="null" @uploaded="handleUploaded" />
+
+ <!-- ============ 鍒嗙被绠$悊 ============ -->
+ <div class="files-list-header">
+ <span class="files-list-title">
+ 鎴戠殑鍒嗙被锛坽{ categories.length }}锛�
+ <span class="title-hint">瀵硅瘽鏃跺彲鎸夊垎绫绘暣浣撶粦瀹�</span>
+ </span>
+ <n-button size="tiny" quaternary @click="showCreateCategory = true">+ 鏂板缓鍒嗙被</n-button>
+ </div>
+
+ <div v-if="categories.length === 0" class="empty-hint category-empty">
+ 杩樻病鏈夊垎绫汇�傚缓涓�涓垎绫伙紝鎶婃枃妗e綊杩涘幓锛屽璇濇椂灏辫兘涓�閿粦瀹氭暣绫汇��
+ </div>
+ <div v-for="cat in categories" v-else :key="cat.id" class="category-row">
+ <div class="category-row-main">
+ <div class="category-name">
+ {{ cat.name }}
+ <span v-if="cat.isGlobal" class="global-badge">鍏ㄥ眬</span>
+ </div>
+ <div class="category-meta">
+ {{ cat.ingestedCount }}/{{ cat.fileCount }} 绡囧凡鍏ュ簱
+ <span v-if="cat.description"> 路 {{ cat.description }}</span>
+ </div>
+ </div>
+ <div class="category-row-actions">
+ <n-button size="tiny" quaternary @click="startRenameCategory(cat)">閲嶅懡鍚�</n-button>
+ <n-button size="tiny" type="error" quaternary @click="handleDeleteCategory(cat)">
+ 鍒犻櫎
+ </n-button>
+ </div>
+ </div>
+
+ <!-- ============ 鏂囨。鍒楄〃锛堟寜鍒嗙被鍒嗙粍锛�============ -->
+ <div class="files-list-header">
+ <span class="files-list-title">鎴戠殑鏂囨。锛坽{ files.length }}锛�</span>
+ <n-button size="tiny" quaternary :loading="loading" @click="load">鍒锋柊</n-button>
+ </div>
+
+ <n-spin v-if="loading" size="small" class="files-spin" />
+
+ <div v-else-if="files.length === 0" class="empty-hint files-empty">
+ 杩樻病鏈変笂浼犱换浣曟枃妗�
+ </div>
+
+ <!--
+ 鎸夊垎绫诲垎缁勫睍绀猴紝鑰屼笉鏄竴涓插钩閾虹殑鍗$墖銆�
+ 鐢ㄦ埛鏈�闇�瑕佷竴鐪肩湅鍑恒�岃繖绡囧湪鍝釜鍒嗙被閲屻�嶏紝
+ 骞抽摵鍒楄〃涓婂啀鎸備釜鏍囩浠嶇劧瑕佹壘锛涘垎缁勫垯鏄洿鎺ュ彲瑙佺殑缁撴瀯銆�
+ -->
+ <template v-for="group in groupedFiles" v-else :key="group.key">
+ <div class="group-header">
+ <span class="group-name">
+ {{ group.name }}
+ <span v-if="group.isGlobal" class="global-badge">鍏ㄥ眬</span>
+ </span>
+ <span class="group-count">{{ group.files.length }} 绡�</span>
+ </div>
+
+ <div v-for="file in group.files" :key="file.id" class="file-card">
+ <div class="file-card-main">
+ <div class="file-name">{{ file.filename }}</div>
+ <div class="file-meta">
+ <span>{{ formatSize(file.fileSize) }}</span>
+ <span class="file-sep">路</span>
+ <span>{{ formatDate(file.createdAt) }}</span>
+ <span class="file-sep">路</span>
+ <span v-if="file.ingested" class="status-ok">
+ 宸插叆搴� {{ file.chunkCount }} 涓墖娈�
+ </span>
+ <span v-else-if="ingestFailed(file)" class="status-fail">
+ 鍏ュ簱澶辫触锛歿{ file.ingestMessage }}
+ </span>
+ <span v-else class="status-pending">鏈悜閲忓寲</span>
+ </div>
+ </div>
+
+ <div class="file-card-actions">
+ <!-- 褰掔被锛氭渶甯歌鎿嶄綔锛屾斁鍦ㄦ渶鍓嶉潰 -->
+ <n-select
+ :value="file.categoryId"
+ size="tiny"
+ class="category-select"
+ :options="categoryOptions"
+ placeholder="鏈垎绫�"
+ :consistent-menu-width="false"
+ @update:value="(v) => handleAssign(file, v)"
+ />
+ <n-button
+ v-if="!file.ingested"
+ size="small"
+ :loading="ingestingId === file.id"
+ @click="handleIngest(file)"
+ >
+ 鍚戦噺鍖�
+ </n-button>
+ <n-button v-else size="small" :loading="ingestingId === file.id" @click="handleIngest(file)">
+ 閲嶆柊鍏ュ簱
+ </n-button>
+ <n-button size="small" type="error" quaternary @click="handleDelete(file)">
+ 鍒犻櫎
+ </n-button>
+ </div>
+ </div>
+ </template>
+ </div>
+
+ <!-- 鏂板缓鍒嗙被 -->
+ <n-modal v-model:show="showCreateCategory" preset="card" title="鏂板缓鍒嗙被" class="cat-modal" :bordered="false">
+ <n-form label-placement="top">
+ <n-form-item label="鍒嗙被鍚嶇О">
+ <n-input v-model:value="newCategoryName" placeholder="渚嬪锛氬璇濇枃妗c�佷骇鍝佽祫鏂�"
+ maxlength="64" show-count @keyup.enter="handleCreateCategory" />
+ </n-form-item>
+ <n-form-item label="璇存槑锛堝彲閫夛級">
+ <n-input v-model:value="newCategoryDesc" placeholder="渚夸簬鑷繁鏃ュ悗鍒嗚鲸杩欎釜鍒嗙被瑁呬粈涔�"
+ maxlength="255" />
+ </n-form-item>
+ <n-form-item v-if="isAdmin" label="鍙鑼冨洿">
+ <n-radio-group v-model:value="newCategoryGlobal">
+ <n-radio :value="false">浠呰嚜宸�</n-radio>
+ <n-radio :value="true">鎵�鏈夌敤鎴凤紙鍏ㄥ眬鍒嗙被锛岄渶绠$悊鍛橈級</n-radio>
+ </n-radio-group>
+ </n-form-item>
+ </n-form>
+ <template #footer>
+ <div class="modal-footer">
+ <n-button size="small" @click="showCreateCategory = false">鍙栨秷</n-button>
+ <n-button size="small" type="primary" :loading="creatingCategory" @click="handleCreateCategory">
+ 鍒涘缓
+ </n-button>
+ </div>
+ </template>
+ </n-modal>
+
+ <!-- 閲嶅懡鍚嶅垎绫� -->
+ <n-modal v-model:show="showRenameCategory" preset="card" title="閲嶅懡鍚嶅垎绫�" class="cat-modal" :bordered="false">
+ <n-form label-placement="top">
+ <n-form-item label="鍒嗙被鍚嶇О">
+ <n-input v-model:value="renameValue" maxlength="64" @keyup.enter="handleRenameCategory" />
+ </n-form-item>
+ </n-form>
+ <template #footer>
+ <div class="modal-footer">
+ <n-button size="small" @click="showRenameCategory = false">鍙栨秷</n-button>
+ <n-button size="small" type="primary" :loading="renaming" @click="handleRenameCategory">
+ 淇濆瓨
+ </n-button>
+ </div>
+ </template>
+ </n-modal>
+ </div>
+</template>
+
+<script setup>
+import { computed, onMounted, ref } from 'vue'
+import {
+ NAlert,
+ NButton,
+ NForm,
+ NFormItem,
+ NInput,
+ NModal,
+ NRadio,
+ NRadioGroup,
+ NSelect,
+ NSpin,
+ NTag,
+ useDialog,
+ useMessage
+} from 'naive-ui'
+import FileUpload from '@/components/FileUpload.vue'
+import { deleteFile, ingestFile, listFiles, ragHealth } from '@/api/fileApi'
+import {
+ assignFileToCategory,
+ createCategory,
+ deleteCategory,
+ listCategories,
+ updateCategory
+} from '@/api/categoryApi'
+import { useAuthStore } from '@/stores/authStore'
+
+const message = useMessage()
+const dialog = useDialog()
+const auth = useAuthStore()
+
+const files = ref([])
+const categories = ref([])
+const loading = ref(false)
+const ingestingId = ref(null)
+const ragEnabled = ref(true)
+const ragAvailable = ref(true)
+const ragBaseUrl = ref('')
+
+const isAdmin = computed(() => auth.isAdmin)
+
+// ---------------- 鍒嗙被寮圭獥鐘舵�� ----------------
+const showCreateCategory = ref(false)
+const newCategoryName = ref('')
+const newCategoryDesc = ref('')
+const newCategoryGlobal = ref(false)
+const creatingCategory = ref(false)
+
+const showRenameCategory = ref(false)
+const renameTarget = ref(null)
+const renameValue = ref('')
+const renaming = ref(false)
+
+const categoryOptions = computed(() => [
+ { label: '鏈垎绫�', value: null },
+ ...categories.value.map((c) => ({
+ label: c.isGlobal ? `${c.name}锛堝叏灞�锛塦 : c.name,
+ value: c.id
+ }))
+])
+
+/**
+ * 鎸夊垎绫绘妸鏂囨。鍒嗙粍灞曠ず銆�
+ *
+ * 鏈垎绫荤殑鎺掑湪鏈�鍚� 鈥斺�� 瀹冩槸銆屽緟鏁寸悊銆嶇姸鎬侊紝
+ * 鏀炬渶鍓嶉潰浼氭尋鎺夌敤鎴峰凡缁忔暣鐞嗗ソ鐨勫唴瀹广��
+ */
+const groupedFiles = computed(() => {
+ const groups = []
+ const byCategory = new Map()
+
+ // 鎸夊垎绫诲垪琛ㄩ『搴忓缓缁勶紝淇濊瘉绌哄垎绫讳篃鑳芥樉绀哄嚭鏉ワ紙鎻愮ず鐢ㄦ埛瀹冭繕娌″唴瀹癸級
+ for (const cat of categories.value) {
+ const g = { key: `c${cat.id}`, name: cat.name, isGlobal: cat.isGlobal, files: [] }
+ byCategory.set(cat.id, g)
+ groups.push(g)
+ }
+
+ const uncategorized = { key: 'none', name: '鏈垎绫�', isGlobal: false, files: [] }
+
+ for (const file of files.value) {
+ const g = file.categoryId != null ? byCategory.get(file.categoryId) : null
+ if (g) {
+ g.files.push(file)
+ } else {
+ // 鍒嗙被琚垹鎺夊悗鏂囦欢浼氬彉鍥炴湭鍒嗙被锛岃繖閲屽厹浣�
+ uncategorized.files.push(file)
+ }
+ }
+
+ // 绌哄垎绫讳笉鏄剧ず鍒嗙粍鏍囬锛堝惁鍒欑晫闈笂浼氬鍑轰竴鍫嗐��0 绡囥�嶇殑绌哄3锛�
+ const visible = groups.filter((g) => g.files.length > 0)
+ if (uncategorized.files.length > 0) {
+ visible.push(uncategorized)
+ }
+ return visible
+})
+
+onMounted(load)
+
+async function load() {
+ loading.value = true
+ try {
+ const [health, list, cats] = await Promise.all([
+ ragHealth(),
+ listFiles(null),
+ listCategories()
+ ])
+ ragEnabled.value = health.enabled !== false
+ ragAvailable.value = health.available !== false
+ ragBaseUrl.value = health.baseUrl || ''
+ files.value = list || []
+ categories.value = cats || []
+ } catch (error) {
+ message.error(error.message || '鍔犺浇澶辫触')
+ } finally {
+ loading.value = false
+ }
+}
+
+function handleUploaded(uploaded) {
+ files.value = [...uploaded, ...files.value]
+}
+
+async function handleIngest(file) {
+ ingestingId.value = file.id
+ try {
+ const updated = await ingestFile(file.id)
+ const index = files.value.findIndex((item) => item.id === file.id)
+ if (index !== -1) {
+ files.value[index] = updated
+ }
+ message.success(`鍚戦噺鍖栧畬鎴愶紝鍏� ${updated.chunkCount} 涓墖娈礰)
+ } catch (error) {
+ message.error(error.message || '鍚戦噺鍖栧け璐�')
+ // 澶辫触鍚庡埛鏂帮紝鏄剧ず鍚庣璁板綍鐨勫け璐ュ師鍥�
+ try {
+ files.value = await listFiles(null)
+ } catch {
+ // 蹇界暐
+ }
+ } finally {
+ ingestingId.value = null
+ }
+}
+
+function handleDelete(file) {
+ dialog.warning({
+ title: '鍒犻櫎鏂囨。',
+ content: `纭畾鍒犻櫎銆�${file.filename}銆嶅悧锛熺鐩樻枃浠朵笌宸插叆搴撶殑鍚戦噺閮戒細琚竻鐞嗐�俙,
+ positiveText: '鍒犻櫎',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await deleteFile(file.id)
+ files.value = files.value.filter((item) => item.id !== file.id)
+ message.success('宸插垹闄�')
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎澶辫触')
+ }
+ }
+ })
+}
+
+function ingestFailed(file) {
+ return Boolean(file.ingestMessage) && !file.ingested
+}
+
+// ---------------- 鍒嗙被鎿嶄綔 ----------------
+
+async function handleCreateCategory() {
+ const name = newCategoryName.value.trim()
+ if (!name) {
+ message.warning('璇疯緭鍏ュ垎绫诲悕绉�')
+ return
+ }
+ creatingCategory.value = true
+ try {
+ const created = await createCategory(name, newCategoryDesc.value || null, newCategoryGlobal.value)
+ categories.value = [...categories.value, created]
+ message.success(`鍒嗙被銆�${created.name}銆嶅凡鍒涘缓锛屽彲鎶婃枃妗e綊鍏ュ叾涓璥)
+
+ showCreateCategory.value = false
+ newCategoryName.value = ''
+ newCategoryDesc.value = ''
+ newCategoryGlobal.value = false
+ } catch (error) {
+ message.error(error.message || '鍒涘缓澶辫触')
+ } finally {
+ creatingCategory.value = false
+ }
+}
+
+function startRenameCategory(cat) {
+ renameTarget.value = cat
+ renameValue.value = cat.name
+ showRenameCategory.value = true
+}
+
+async function handleRenameCategory() {
+ const name = renameValue.value.trim()
+ if (!name) {
+ message.warning('璇疯緭鍏ュ垎绫诲悕绉�')
+ return
+ }
+ renaming.value = true
+ try {
+ const updated = await updateCategory(renameTarget.value.id, name, renameTarget.value.description)
+ categories.value = categories.value.map((c) => (c.id === updated.id ? updated : c))
+ // 鏂囨。鍒楄〃閲岀殑鍒嗙被鍚嶄篃瑕佸悓姝ワ紝鍚﹀垯鍒嗙粍鏍囬浼氫笌鍒嗙被鍒楄〃涓嶄竴鑷�
+ files.value = files.value.map((f) =>
+ f.categoryId === updated.id ? { ...f, categoryName: updated.name } : f
+ )
+ message.success('宸查噸鍛藉悕')
+ showRenameCategory.value = false
+ } catch (error) {
+ message.error(error.message || '閲嶅懡鍚嶅け璐�')
+ } finally {
+ renaming.value = false
+ }
+}
+
+function handleDeleteCategory(cat) {
+ dialog.warning({
+ title: '鍒犻櫎鍒嗙被',
+ content:
+ `纭畾鍒犻櫎鍒嗙被銆�${cat.name}銆嶅悧锛焅n\n` +
+ `鍒嗙被鍐呯殑 ${cat.fileCount} 绡囨枃妗�**涓嶄細琚垹闄�**锛屽彧浼氬彉鎴愩�屾湭鍒嗙被銆嶃�俙,
+ positiveText: '鍒犻櫎鍒嗙被',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await deleteCategory(cat.id)
+ categories.value = categories.value.filter((c) => c.id !== cat.id)
+ // 杩欎簺鏂囨。鍙樺洖鏈垎绫�
+ files.value = files.value.map((f) =>
+ f.categoryId === cat.id ? { ...f, categoryId: null, categoryName: null } : f
+ )
+ message.success('鍒嗙被宸插垹闄わ紝鏂囨。淇濈暀')
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎澶辫触')
+ }
+ }
+ })
+}
+
+/** 鎶婃枃妗gЩ鍏� / 绉诲嚭鍒嗙被 */
+async function handleAssign(file, categoryId) {
+ try {
+ if (categoryId == null) {
+ // 绉诲嚭鍒嗙被锛氬�熺敤褰撳墠鍒嗙被鐨� assign=false
+ if (file.categoryId != null) {
+ await assignFileToCategory(file.categoryId, file.id, false)
+ }
+ } else {
+ await assignFileToCategory(categoryId, file.id, true)
+ }
+
+ const target = categories.value.find((c) => c.id === categoryId)
+ files.value = files.value.map((f) =>
+ f.id === file.id
+ ? { ...f, categoryId: categoryId ?? null, categoryName: target ? target.name : null }
+ : f
+ )
+ // 鍒嗙被鐨勬枃妗f暟鍙樹簡锛岄噸鏂版媺涓�娆′繚璇佺粺璁″噯纭�
+ categories.value = (await listCategories()) || []
+ message.success(categoryId == null ? '宸茬Щ鍑哄垎绫�' : `宸插綊鍏ャ��${target.name}銆峘)
+ } catch (error) {
+ message.error(error.message || '褰掔被澶辫触')
+ await load()
+ }
+}
+
+function formatSize(bytes) {
+ if (!bytes && bytes !== 0) return '-'
+ if (bytes < 1024) return `${bytes} B`
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`
+}
+
+function formatDate(value) {
+ if (!value) return '-'
+ try {
+ return new Date(value).toLocaleString('zh-CN', {
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ hour: '2-digit',
+ minute: '2-digit'
+ })
+ } catch {
+ return String(value)
+ }
+}
+</script>
+
+<style scoped>
+.files-page {
+ height: 100vh;
+ overflow-y: auto;
+ background: var(--bg-page);
+}
+
+.files-header {
+ display: flex;
+ align-items: center;
+ gap: 14px;
+ padding: 14px 24px;
+ border-bottom: 1px solid var(--border-color);
+ position: sticky;
+ top: 0;
+ background: var(--bg-page);
+ z-index: 10;
+}
+
+.files-title {
+ margin: 0;
+ font-size: 16px;
+ font-weight: 600;
+}
+
+.files-header-right {
+ margin-left: auto;
+}
+
+.files-body {
+ max-width: 860px;
+ margin: 0 auto;
+ padding: 24px;
+}
+
+.files-alert {
+ margin-bottom: 16px;
+ font-size: 12.5px;
+ line-height: 1.8;
+}
+
+.title-hint {
+ font-weight: 400;
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-left: 6px;
+}
+
+.category-empty {
+ padding: 20px 0;
+ line-height: 1.9;
+}
+
+.category-row {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+ padding: 12px 14px;
+ border: 1px solid var(--border-color);
+ border-radius: 10px;
+ margin-bottom: 8px;
+ background: #fcfcfd;
+}
+
+.category-row-main {
+ min-width: 0;
+ flex: 1;
+}
+
+.category-name {
+ font-size: 13.5px;
+ font-weight: 500;
+}
+
+.category-meta {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 4px;
+}
+
+.category-row-actions {
+ display: flex;
+ gap: 4px;
+ flex-shrink: 0;
+}
+
+/* 鍒嗙粍鏍囬锛氳銆岃繖绡囧湪鍝釜鍒嗙被銆嶄竴鐪煎彲瑙� */
+.group-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 4px 2px 8px;
+ margin-top: 14px;
+ border-bottom: 1px solid var(--border-color);
+}
+
+.group-name {
+ font-size: 12.5px;
+ font-weight: 600;
+ color: var(--text-secondary);
+}
+
+.group-count {
+ font-size: 11.5px;
+ color: var(--text-muted);
+}
+
+.category-select {
+ width: 130px;
+}
+
+.global-badge {
+ display: inline-block;
+ margin-left: 6px;
+ padding: 0 5px;
+ font-size: 11px;
+ line-height: 16px;
+ border-radius: 4px;
+ color: #0f766e;
+ background: #ecfdf5;
+ vertical-align: middle;
+}
+
+.cat-modal {
+ width: 440px;
+}
+
+.modal-footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: 8px;
+}
+
+.files-list-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin: 26px 0 10px;
+}
+
+.files-list-title {
+ font-size: 13px;
+ font-weight: 600;
+}
+
+.files-spin {
+ display: flex;
+ justify-content: center;
+ padding: 24px 0;
+}
+
+.files-empty {
+ padding: 32px 0;
+}
+
+.file-card {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+ padding: 14px 16px;
+ border: 1px solid var(--border-color);
+ border-radius: 10px;
+ margin-bottom: 10px;
+}
+
+.file-card-main {
+ min-width: 0;
+ flex: 1;
+}
+
+.file-name {
+ font-size: 13.5px;
+ font-weight: 500;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.file-meta {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 5px;
+}
+
+.file-sep {
+ margin: 0 6px;
+}
+
+.status-ok {
+ color: #0f766e;
+}
+
+.status-fail {
+ color: #dc2626;
+}
+
+.status-pending {
+ color: #b45309;
+}
+
+.file-collection {
+ font-size: 11.5px;
+ color: var(--text-muted);
+ margin-top: 5px;
+}
+
+.file-collection code {
+ background: var(--code-bg);
+ padding: 1px 5px;
+ border-radius: 4px;
+}
+
+.file-card-actions {
+ display: flex;
+ gap: 6px;
+ flex-shrink: 0;
+}
+</style>
diff --git a/src/views/Login.vue b/src/views/Login.vue
new file mode 100644
index 0000000..d7a3f9d
--- /dev/null
+++ b/src/views/Login.vue
@@ -0,0 +1,227 @@
+<template>
+ <div class="login-page">
+ <n-card class="login-card" :bordered="false">
+ <div class="login-header">
+ <div class="login-logo">CW</div>
+ <h1 class="login-title">Custom-WebUI</h1>
+ <p class="login-subtitle">
+ {{ mode === 'login' ? '鐧诲綍浠ョ户缁綘鐨勫璇�' : '鍒涘缓涓�涓柊璐﹀彿' }}
+ </p>
+ </div>
+
+ <n-form
+ ref="formRef"
+ :model="form"
+ :rules="rules"
+ label-placement="top"
+ size="large"
+ @submit.prevent="handleSubmit"
+ >
+ <n-form-item label="鐢ㄦ埛鍚�" path="username">
+ <n-input
+ v-model:value="form.username"
+ placeholder="璇疯緭鍏ョ敤鎴峰悕"
+ :input-props="{ autocomplete: 'username' }"
+ @keyup.enter="handleSubmit"
+ />
+ </n-form-item>
+
+ <n-form-item v-if="mode === 'register'" label="閭锛堝彲閫夛級" path="email">
+ <n-input v-model:value="form.email" placeholder="you@example.com" />
+ </n-form-item>
+
+ <n-form-item label="瀵嗙爜" path="password">
+ <n-input
+ v-model:value="form.password"
+ type="password"
+ show-password-on="click"
+ placeholder="璇疯緭鍏ュ瘑鐮�"
+ :input-props="{ autocomplete: 'current-password' }"
+ @keyup.enter="handleSubmit"
+ />
+ </n-form-item>
+
+ <!--
+ 鍙繚鐣� attr-type="submit"锛�**涓嶈**鍐嶅姞 @click="handleSubmit"銆�
+ 涓よ�呭悓鏃跺瓨鍦ㄦ椂涓�娆$偣鍑讳細瑙﹀彂涓ゆ鎻愪氦锛氭寜閽� click 涓�娆°��
+ 琛ㄥ崟 submit 涓�娆°�傝〃鐜颁负銆屾敞鍐屾垚鍔熴�嶅拰銆岀敤鎴峰悕宸茶鍗犵敤銆嶅悓鏃跺脊鍑� 鈥斺��
+ 绗竴娆¤姹傜湡鐨勬妸鐢ㄦ埛寤哄ソ浜嗭紝绗簩娆℃墠鍙戠幇閲嶅悕銆�
+ -->
+ <n-button
+ type="primary"
+ block
+ size="large"
+ :loading="loading"
+ attr-type="submit"
+ >
+ {{ mode === 'login' ? '鐧诲綍' : '娉ㄥ唽' }}
+ </n-button>
+ </n-form>
+
+ <div class="login-switch">
+ <n-button text type="primary" @click="toggleMode">
+ {{ mode === 'login' ? '娌℃湁璐﹀彿锛熷幓娉ㄥ唽' : '宸叉湁璐﹀彿锛熷幓鐧诲綍' }}
+ </n-button>
+ </div>
+
+ <n-alert v-if="mode === 'login'" type="info" :bordered="false" class="login-tip">
+ 婕旂ず璐﹀彿锛�<strong>admin / admin123</strong>
+ </n-alert>
+ </n-card>
+ </div>
+</template>
+
+<script setup>
+import { computed, ref } from 'vue'
+import { useRoute, useRouter } from 'vue-router'
+import {
+ NAlert,
+ NButton,
+ NCard,
+ NForm,
+ NFormItem,
+ NInput,
+ useMessage
+} from 'naive-ui'
+import { useAuthStore } from '@/stores/authStore'
+
+const router = useRouter()
+const route = useRoute()
+const message = useMessage()
+const auth = useAuthStore()
+
+const mode = ref('login')
+const formRef = ref(null)
+const loading = computed(() => auth.loading)
+
+const form = ref({
+ username: '',
+ password: '',
+ email: ''
+})
+
+const rules = {
+ username: [
+ { required: true, message: '璇疯緭鍏ョ敤鎴峰悕', trigger: ['input', 'blur'] },
+ { min: 3, max: 64, message: '鐢ㄦ埛鍚嶉暱搴﹂渶鍦� 3-64 涔嬮棿', trigger: 'blur' }
+ ],
+ password: [
+ { required: true, message: '璇疯緭鍏ュ瘑鐮�', trigger: ['input', 'blur'] },
+ { min: 6, message: '瀵嗙爜鑷冲皯 6 浣�', trigger: 'blur' }
+ ],
+ email: [{ type: 'email', message: '閭鏍煎紡涓嶆纭�', trigger: 'blur' }]
+}
+
+function toggleMode() {
+ mode.value = mode.value === 'login' ? 'register' : 'login'
+ formRef.value?.restoreValidation()
+}
+
+/**
+ * 鎻愪氦涓爣蹇椼��
+ *
+ * 鍗充娇宸茬粡鍘绘帀浜嗘寜閽笂鐨勯噸澶嶇粦瀹氾紝杩欓噷浠嶇劧闇�瑕佷竴涓悓姝ョ殑銆佽嚜宸辩淮鎶ょ殑
+ * 瀹堝崼锛歚auth.loading` 鏄紓姝ュ搷搴斿紡鐨勶紝鎸夐挳鐨� disabled/loading 鐘舵��
+ * 瑕佺瓑鍒颁笅涓�娆℃覆鏌撴墠鐢熸晥锛屾湡闂磋繛鐐规垨鍥炶溅+鐐瑰嚮骞跺彂浠嶅彲鑳界┛杩囥��
+ * 鐢ㄦ櫘閫氬彉閲忥紙闈� ref锛夊仛闂搁棬锛岃兘淇濊瘉鍦ㄥ悓涓�浜嬩欢寰幆鍐呯珛鍗崇敓鏁堛��
+ */
+let submitting = false
+
+async function handleSubmit() {
+ if (submitting) return
+
+ try {
+ // validate 澶辫触浼� reject锛岃繖閲岀粺涓�浜ょ粰 catch 澶勭悊
+ await formRef.value?.validate()
+ } catch {
+ return
+ }
+
+ submitting = true
+ try {
+ if (mode.value === 'login') {
+ await auth.login({
+ username: form.value.username,
+ password: form.value.password
+ })
+ message.success('鐧诲綍鎴愬姛')
+
+ // 鐧诲綍鍓嶅鏋滆瀹堝崼鎷︿笅锛岀櫥褰曞悗鍥炲埌鍘熸潵鎯冲幓鐨勯〉闈�
+ const redirect = route.query.redirect
+ router.replace(typeof redirect === 'string' && redirect ? redirect : '/c')
+ } else {
+ await auth.register({
+ username: form.value.username,
+ password: form.value.password,
+ email: form.value.email || undefined
+ })
+ message.success('娉ㄥ唽鎴愬姛锛岃鐧诲綍')
+ mode.value = 'login'
+ form.value.password = ''
+ }
+ } catch (error) {
+ message.error(error.message || '鎿嶄綔澶辫触')
+ } finally {
+ submitting = false
+ }
+}
+</script>
+
+<style scoped>
+.login-page {
+ height: 100vh;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: linear-gradient(140deg, #f8fafc 0%, #eef2f7 60%, #e8edf3 100%);
+}
+
+.login-card {
+ width: 400px;
+ box-shadow: 0 10px 40px rgba(15, 23, 42, 0.08);
+ border-radius: 14px;
+ padding: 8px;
+}
+
+.login-header {
+ text-align: center;
+ margin-bottom: 24px;
+}
+
+.login-logo {
+ width: 52px;
+ height: 52px;
+ margin: 0 auto 14px;
+ border-radius: 14px;
+ background: #374151;
+ color: #fff;
+ font-weight: 700;
+ font-size: 19px;
+ letter-spacing: 0.5px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.login-title {
+ margin: 0 0 6px;
+ font-size: 22px;
+ font-weight: 600;
+}
+
+.login-subtitle {
+ margin: 0;
+ font-size: 13px;
+ color: var(--text-secondary);
+}
+
+.login-switch {
+ text-align: center;
+ margin-top: 16px;
+}
+
+.login-tip {
+ margin-top: 18px;
+ font-size: 13px;
+}
+</style>
--
Gitblit v1.9.1