diff --git a/.gitignore b/.gitignore index cb8e9674..07699e34 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ docs/ venv/ backend/venv/ env/ -.env +# .env .venv build/ develop-eggs/ diff --git a/backend/.env b/backend/.env new file mode 100644 index 00000000..80f12a39 --- /dev/null +++ b/backend/.env @@ -0,0 +1,2 @@ +INTEGRATION_API_BASE=http://192.168.100.230:8891 +INTEGRATION_API_KEY=I76mSQZQEPYU6TubMhjh-xLsCgWC0gSIg5MncJFHFCvqvVlg-gZ_BvwO_UEL2nh diff --git a/backend/app/api/chat.py b/backend/app/api/chat.py index 0dbd56cf..095996f3 100644 --- a/backend/app/api/chat.py +++ b/backend/app/api/chat.py @@ -253,12 +253,12 @@ def submit_feedback(): return jsonify({'error': 'Missing user or agent context'}), 500 # 构造查询:限定在当前用户和 Agent 范围内 - query = ChatLog.query.filter_by(user_id=user.id, agent_id=agent.id) + chat_logs_query = db.session.query(ChatLog).filter_by(user_id=user.id, agent_id=agent.id) if conversation_id: - query = query.filter_by(conversation_id=conversation_id) + chat_logs_query = chat_logs_query.filter_by(conversation_id=conversation_id) # 取最新一条对话日志 - chat_log = query.order_by(ChatLog.created_at.desc()).first() + chat_log = chat_logs_query.order_by(ChatLog.created_at.desc()).first() if not chat_log: return jsonify({'error': 'ChatLog not found'}), 404 diff --git a/backend/app/config.py b/backend/app/config.py index 6aeb809b..27c838a7 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -72,6 +72,7 @@ class DevelopmentConfig(Config): DEBUG = True SQLALCHEMY_DATABASE_URI = os.getenv( 'DATABASE_URL', + # 'postgresql://postgres:123456@8.152.207.171:5432/hxops_db', 'postgresql://postgres:difyai123456@localhost:5432/hxops_db', ) diff --git a/backend/app/services/dify.py b/backend/app/services/dify.py index 879ea889..1930f323 100644 --- a/backend/app/services/dify.py +++ b/backend/app/services/dify.py @@ -129,7 +129,9 @@ class DifyService: DifyService._collect_metadata(retriever_resources, attribution_parts, data) elif event in ('message_end', 'agent_message', 'workflow_finished'): - if data.get('answer'): + # Keep metadata from non-message events, but avoid appending + # intermediate workflow/agent outputs into final user answer. + if event == 'message_end' and data.get('answer'): full_answer.append(data.get('answer', '')) DifyService._collect_metadata(retriever_resources, attribution_parts, data) diff --git a/frontend/dist/index.html b/frontend/dist/index.html index d45ce5c3..89620a59 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -7,13 +7,14 @@ - + - hxai - - + AI工作台 + +
+ diff --git a/frontend/index.html b/frontend/index.html index 92532730..7bc203dd 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -7,9 +7,9 @@ - + - hxai + AI工作台
diff --git a/frontend/src/App.vue b/frontend/src/App.vue index f8194e3f..82b31877 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -3,9 +3,18 @@ import { useI18n } from 'vue-i18n'; import { watch, onMounted } from 'vue'; import { useTheme } from './composables/useTheme'; +import LevelMessageDialog from './components/LevelMessageDialog.vue'; +import { useGlobalMessageDialog } from './composables/useGlobalMessageDialog'; const { locale } = useI18n(); const { themePreference, initTheme, setThemePreference } = useTheme(); +const { + messageDialogVisible, + messageDialogLevel, + messageDialogTitle, + messageDialogContent, + closeMessageDialog, +} = useGlobalMessageDialog(); const getAuthHeaders = () => { const candidates = [ @@ -96,4 +105,11 @@ onMounted(async () => { diff --git a/frontend/src/components/DeleteConfirmDialog.vue b/frontend/src/components/DeleteConfirmDialog.vue new file mode 100644 index 00000000..2e12a34e --- /dev/null +++ b/frontend/src/components/DeleteConfirmDialog.vue @@ -0,0 +1,192 @@ + + + + + diff --git a/frontend/src/components/FilePreviewModal.vue b/frontend/src/components/FilePreviewModal.vue index d5c655e7..82b21d08 100644 --- a/frontend/src/components/FilePreviewModal.vue +++ b/frontend/src/components/FilePreviewModal.vue @@ -345,13 +345,13 @@ watch( diff --git a/frontend/src/composables/useChat.ts b/frontend/src/composables/useChat.ts index 1446f9e7..7e72d3e9 100644 --- a/frontend/src/composables/useChat.ts +++ b/frontend/src/composables/useChat.ts @@ -149,7 +149,7 @@ export function useChat() { * 用途:发送消息并处理 SSE 流式响应 * 核心逻辑: * 1. 乐观更新 UI (立即显示用户消息) - * 2. 创建空的 AI 消息占位 + * 2. Create assistant message lazily only after receiving real answer chunks. * 3. 发起 Fetch POST 请求 * 4. 获取 Reader 流式读取 * 5. 逐块解码并追加到当前 AI 消息中 @@ -165,13 +165,19 @@ export function useChat() { }); // 1. 乐观 UI 更新:立即将用户消息推入列表 messages.value.push({ role: 'user', content: query }); - // 创建一个空的 Assistant 消息用于流式追加,并记录其索引 - const botMsgIndex = messages.value.push({ - role: 'assistant', - content: '', - retriever_resources: [], - attribution_parts: [] - }) - 1; + // Lazily create assistant message only when answer/error arrives. + let botMsgIndex: number | null = null; + const ensureBotMessage = () => { + if (botMsgIndex === null) { + botMsgIndex = messages.value.push({ + role: 'assistant', + content: '', + retriever_resources: [], + attribution_parts: [] + }) - 1; + } + return messages.value[botMsgIndex] || null; + }; isThinking.value = true; @@ -232,8 +238,6 @@ export function useChat() { try { const data = JSON.parse(payload); - const botMsg = messages.value[botMsgIndex]; - if (!botMsg) continue; console.debug('[chat][sse] event', { event: data?.event, answerLength: typeof data?.answer === 'string' ? data.answer.length : 0, @@ -241,10 +245,10 @@ export function useChat() { conversationId: data?.conversation_id || conversationId.value, }); - if (data.event === 'message' || data.event === 'agent_message') { - // event: message LLM 返回文本块事件,即:完整的文本以分块的方式输出。 + if (data.event === 'message') { if (typeof data.answer === 'string' && data.answer.length > 0) { - // answer: LLM 返回文本块内容 + const botMsg = ensureBotMessage(); + if (!botMsg) continue; botMsg.content += data.answer; console.debug('[chat][sse] append answer chunk', { event: data.event, @@ -252,13 +256,19 @@ export function useChat() { total: botMsg.content.length, }); } - applyEventMetadata(botMsg, data); - } else if (data.event === 'message_end' || data.event === 'workflow_finished') { + if (botMsgIndex !== null) { + const currentBotMsg = messages.value[botMsgIndex]; + if (currentBotMsg) { + applyEventMetadata(currentBotMsg, data); + } + } + } else if (data.event === 'message_end') { if (data.conversation_id) { conversationId.value = data.conversation_id; } - // Some providers may put final answer on message_end/workflow events. if (typeof data.answer === 'string' && data.answer.length > 0) { + const botMsg = ensureBotMessage(); + if (!botMsg) continue; botMsg.content += data.answer; console.debug('[chat][sse] append final answer', { event: data.event, @@ -266,8 +276,15 @@ export function useChat() { total: botMsg.content.length, }); } - applyEventMetadata(botMsg, data); + if (botMsgIndex !== null) { + const currentBotMsg = messages.value[botMsgIndex]; + if (currentBotMsg) { + applyEventMetadata(currentBotMsg, data); + } + } } else if (data.event === 'error') { + const botMsg = ensureBotMessage(); + if (!botMsg) continue; botMsg.content += `\n[Error: ${data.message}]`; console.error('[chat][sse] backend error event', data); } @@ -279,7 +296,7 @@ export function useChat() { } } catch (e: any) { console.error('[chat][send] failed', e); - const botMsg = messages.value[botMsgIndex]; + const botMsg = ensureBotMessage(); if (botMsg) { botMsg.content += `\n[Error: ${e.message || 'Network Issue'}]`; } diff --git a/frontend/src/composables/useGlobalMessageDialog.ts b/frontend/src/composables/useGlobalMessageDialog.ts new file mode 100644 index 00000000..2961217f --- /dev/null +++ b/frontend/src/composables/useGlobalMessageDialog.ts @@ -0,0 +1,37 @@ +import { readonly, ref } from 'vue'; + +export type MessageLevel = 'success' | 'info' | 'warning' | 'error'; + +// 全局单例状态:整个应用共享一套消息弹框。 +const visible = ref(false); +const level = ref('info'); +const title = ref(''); +const message = ref(''); + +export const useGlobalMessageDialog = () => { + const showMessageDialog = ( + nextLevel: MessageLevel, + nextMessage: string, + nextTitle = '' + ) => { + level.value = nextLevel; + title.value = nextTitle; + message.value = nextMessage; + visible.value = true; + }; + + const closeMessageDialog = () => { + visible.value = false; + title.value = ''; + message.value = ''; + }; + + return { + messageDialogVisible: visible, + messageDialogLevel: readonly(level), + messageDialogTitle: readonly(title), + messageDialogContent: readonly(message), + showMessageDialog, + closeMessageDialog, + }; +}; diff --git a/frontend/src/config.ts b/frontend/src/config.ts index 14ce2de4..5080244c 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -1,5 +1,5 @@ export const config = { - appTitle: 'hxai', + appTitle: 'AI工作台', auth: { wecom: { enabled: true, diff --git a/frontend/src/i18n.ts b/frontend/src/i18n.ts index 228db12a..5f9bf276 100644 --- a/frontend/src/i18n.ts +++ b/frontend/src/i18n.ts @@ -138,10 +138,18 @@ const messages = { } }, common: { - errorOccurred: 'An error occurred' + errorOccurred: 'An error occurred', + deleteDialog: { + defaultTitle: 'Are you sure you want to delete?', + defaultMessage: 'When clicked the OK button, this dialog will be closed after 1 second', + cancel: 'Cancel', + confirm: 'OK' + } }, workspace: { title: 'AI Workspace', + brandTitle: 'Hexin AI Workspace', + languageLabel: 'Language', userTitle: '{username}\'s AI Workspace', subtitle: 'Choose an agent or click a quick question to start', search: 'Search agents...', @@ -156,6 +164,10 @@ const messages = { add: 'Add Quick Question', edit: 'Edit Quick Question', addNew: 'Add New Quick Question', + deleteDialog: { + title: 'Are you sure you want to delete?', + message: 'When clicked the OK button, this dialog will be closed after 1 second' + }, fields: { title: 'Title', titlePlaceholder: 'e.g. Daily Report', @@ -988,8 +1000,19 @@ const messages = { phone: '手机号' } }, + common: { + errorOccurred: '发生错误', + deleteDialog: { + defaultTitle: '您确定要删除吗?', + defaultMessage: '点击“确定”按钮后,该对话框将在 1 秒后关闭', + cancel: '取消', + confirm: '确定' + } + }, workspace: { title: 'AI 工作台', + brandTitle: 'AI工作台', + languageLabel: '语言', userTitle: '{username} 的 AI 工作台', subtitle: '选择一个助手,或点击常用问题快速开始', search: '搜索应用...', @@ -1004,6 +1027,10 @@ const messages = { add: '添加问题', edit: '编辑常用问题', addNew: '添加新常用问题', + deleteDialog: { + title: '您确定要删除吗?', + message: '点击“确定”按钮后,该对话框将在 1 秒后关闭' + }, fields: { title: '标题', titlePlaceholder: '例如:写日报', @@ -1821,8 +1848,19 @@ const messages = { inputError: '請輸入用戶名和密碼', requestFailed: '請求失敗' }, + common: { + errorOccurred: '發生錯誤', + deleteDialog: { + defaultTitle: '您確定要刪除嗎?', + defaultMessage: '點擊「確定」按鈕後,此對話框將在 1 秒後關閉', + cancel: '取消', + confirm: '確定' + } + }, workspace: { title: 'AI 工作台', + brandTitle: 'AI工作台', + languageLabel: '語言', userTitle: '{username} 的 AI 工作台', subtitle: '選擇一個助手,或點擊常用問題快速開始', search: '搜索應用...', @@ -1837,6 +1875,10 @@ const messages = { add: '添加問題', edit: '編輯常用問題', addNew: '添加新常用問題', + deleteDialog: { + title: '您確定要刪除嗎?', + message: '點擊「確定」按鈕後,此對話框將在 1 秒後關閉' + }, fields: { title: '標題', titlePlaceholder: '例如:寫日報', @@ -2659,8 +2701,19 @@ const messages = { inputError: 'กรุณากรอกชื่อผู้ใช้และรหัสผ่าน', requestFailed: 'คำขอล้มเหลว' }, + common: { + errorOccurred: 'เกิดข้อผิดพลาด', + deleteDialog: { + defaultTitle: 'คุณแน่ใจหรือไม่ว่าต้องการลบ?', + defaultMessage: 'เมื่อกดปุ่มตกลง กล่องโต้ตอบนี้จะปิดหลังจาก 1 วินาที', + cancel: 'ยกเลิก', + confirm: 'ตกลง' + } + }, workspace: { title: 'พื้นที่ทำงาน AI', + brandTitle: 'Hexin AI Workspace', + languageLabel: 'ภาษา', userTitle: 'พื้นที่ทำงาน AI ของ {username}', subtitle: 'เลือกผู้ช่วยหรือคลิกคำถามด่วนเพื่อเริ่ม', search: 'ค้นหาตัวแทน...', @@ -2675,6 +2728,10 @@ const messages = { add: 'เพิ่มคำถามด่วน', edit: 'แก้ไขคำถามด่วน', addNew: 'เพิ่มคำถามด่วนใหม่', + deleteDialog: { + title: 'คุณแน่ใจหรือไม่ว่าต้องการลบ?', + message: 'เมื่อกดปุ่มตกลง กล่องโต้ตอบนี้จะปิดหลังจาก 1 วินาที' + }, fields: { title: 'หัวข้อ', titlePlaceholder: 'เช่น รายงานประจำวัน', diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 610a0081..5b48f038 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -7,7 +7,7 @@ import i18n from './i18n' import { config } from './config' // Set document title from config -document.title = config.appTitle || 'hxai'; +document.title = config.appTitle || 'AI工作台'; createApp(App) .use(router) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 804f508d..0123f2c9 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -48,7 +48,7 @@ const router = createRouter({ }); router.afterEach((to) => { - const baseTitle = config.appTitle || 'hxai'; + const baseTitle = config.appTitle || 'AI工作台'; if (to.meta.title) { document.title = `${to.meta.title} - ${baseTitle}`; } else { diff --git a/frontend/src/style.css b/frontend/src/style.css index f4ebedef..a485355b 100644 --- a/frontend/src/style.css +++ b/frontend/src/style.css @@ -101,6 +101,27 @@ @apply bg-white rounded-2xl border border-slate-100 shadow-soft hover:shadow-lg transition-all duration-300; } + /* Mobile-first layout tokens for consistent spacing and density. */ + .page-shell-mobile { + @apply px-3 md:px-8; + } + + .section-gap-mobile { + @apply mb-3 md:mb-8; + } + + .card-mobile-compact { + @apply p-3 sm:p-5; + } + + .icon-box-mobile { + @apply w-8 h-8 sm:w-10 sm:h-10; + } + + .icon-glyph-mobile { + @apply w-4 h-4 sm:w-6 sm:h-6; + } + .badge { @apply px-2.5 py-0.5 rounded-full text-xs font-medium border; } @@ -131,6 +152,15 @@ caret-color: #0891b2; } + .chat-composer-textarea:focus, + .chat-composer-textarea:focus-visible { + outline: none !important; + box-shadow: none !important; + border: 0 !important; + -webkit-appearance: none; + appearance: none; + } + .chat-composer-textarea::selection { background-color: rgba(14, 165, 233, 0.2); } diff --git a/frontend/src/views/AdminView.vue b/frontend/src/views/AdminView.vue index c8468ebc..59807f0a 100644 --- a/frontend/src/views/AdminView.vue +++ b/frontend/src/views/AdminView.vue @@ -1,4 +1,4 @@ - + +