From c1c4efe4f19c439f30fd69801512312994a57e28 Mon Sep 17 00:00:00 2001 From: "RUNNY\\lyl10" <1013397054@qq.com> Date: Fri, 12 Jun 2026 16:44:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(=E7=9F=A5=E8=AF=86=E5=BA=93):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=A3=E5=86=B3ppt=E4=B8=AD=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=A7=A3=E6=9E=90=E5=90=8C=E6=AD=A5dify=E6=97=B6?= =?UTF-8?q?=E5=8E=BB=E6=8E=89base64=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../knowledge_cleaning/dify_sync_service.py | 10 +++ backend/edkb_system/skills/loader_excel.py | 62 ++++++++++++++----- backend/edkb_system/skills/loader_pdf.py | 2 +- backend/requirements.txt | 1 + 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/backend/app/services/knowledge_cleaning/dify_sync_service.py b/backend/app/services/knowledge_cleaning/dify_sync_service.py index 99569c2a..18148b8a 100644 --- a/backend/app/services/knowledge_cleaning/dify_sync_service.py +++ b/backend/app/services/knowledge_cleaning/dify_sync_service.py @@ -6,6 +6,7 @@ from __future__ import annotations from datetime import datetime import hashlib +import re from pathlib import Path import requests @@ -207,6 +208,13 @@ class KbDifySyncService: ) +def _strip_base64_images(text: str) -> str: + """Remove markdown image syntax containing base64 data to avoid token bloat in Dify.""" + # Matches ![alt](data:image/...) + pattern = r'!\[[^\]]*\]\(data:image\/[a-zA-Z]*;base64,[^)]*\)' + return re.sub(pattern, '', text) + + def _load_sync_text(version: KbDocumentVersion) -> tuple[str, str]: candidate_paths = [version.cleaned_file_path, version.cleaned_preview_path, version.source_file_path] for value in candidate_paths: @@ -217,6 +225,8 @@ def _load_sync_text(version: KbDocumentVersion) -> tuple[str, str]: continue text = path.read_text(encoding='utf-8', errors='ignore').strip() if text: + # Strip base64 images before syncing + text = _strip_base64_images(text) return text, str(path) raise KbDifySyncError('没有可用于同步的文本结果') diff --git a/backend/edkb_system/skills/loader_excel.py b/backend/edkb_system/skills/loader_excel.py index e060169c..a2340d7d 100644 --- a/backend/edkb_system/skills/loader_excel.py +++ b/backend/edkb_system/skills/loader_excel.py @@ -9,17 +9,39 @@ from __future__ import annotations from pathlib import Path -from openpyxl import load_workbook +from openpyxl import load_workbook, Workbook from edkb_system.contracts import Context from edkb_system.skills.soffice_util import convert_with_soffice, soffice_candidates +from edkb_system.skills.excel_bridge import convert_with_excel + + +def _convert_xls_to_xlsx_python(path: Path, output: Path) -> Path: + """使用 xlrd 和 openpyxl 进行纯 Python 转换。""" + import xlrd + + book = xlrd.open_workbook(str(path)) + wb = Workbook() + wb.remove(wb.active) # 移除默认的 Sheet + + for i in range(book.nsheets): + sheet = book.sheet_by_index(i) + new_ws = wb.create_sheet(title=sheet.name) + for row in range(sheet.nrows): + # 将 xlrd 的行值(list)追加到 openpyxl 的 sheet 中 + new_ws.append(sheet.row_values(row)) + + wb.save(str(output)) + return output def _convert_xls_to_xlsx(path: Path, out_dir: Path) -> Path: - """将 .xls 转为 .xlsx;soffice 调用带超时,见 EDKB_SOFFICE_TIMEOUT_SEC。""" + """将 .xls 转为 .xlsx。依次尝试 soffice、Excel COM 和 xlrd。""" out_dir.mkdir(parents=True, exist_ok=True) output = out_dir / f"{path.stem}.xlsx" errors: list[str] = [] + + # 1. 尝试 LibreOffice (soffice) for soffice in soffice_candidates(): if not soffice: continue @@ -30,22 +52,31 @@ def _convert_xls_to_xlsx(path: Path, out_dir: Path) -> Path: source_path=path, out_dir=out_dir, ) - except FileNotFoundError: - errors.append(f"soffice not found: {soffice}") - continue - except RuntimeError as exc: - errors.append(str(exc)) - continue - if proc.returncode == 0 and output.exists(): - return output - stderr = (proc.stderr or "").strip() - errors.append( - f"soffice failed ({soffice}, code={proc.returncode}): {stderr or 'no stderr'}" - ) + if proc.returncode == 0 and output.exists(): + return output + stderr = (proc.stderr or "").strip() + errors.append( + f"soffice failed ({soffice}, code={proc.returncode}): {stderr or 'no stderr'}" + ) + except Exception as exc: + errors.append(f"soffice attempt failed ({soffice}): {exc}") + + # 2. Windows 环境下尝试 Excel COM + if os.name == "nt": + try: + return convert_with_excel(path, output) + except Exception as exc: + errors.append(f"Excel COM conversion failed: {exc}") + + # 3. 最后尝试纯 Python (xlrd) + try: + return _convert_xls_to_xlsx_python(path, output) + except Exception as exc: + errors.append(f"Python xlrd conversion failed: {exc}") joined = "; ".join(errors) if errors else "no converter attempted" raise RuntimeError( - ".xls 转 .xlsx 失败。请安装 LibreOffice(soffice)或设置 EDKB_SOFFICE。" + ".xls 转 .xlsx 失败。请安装 LibreOffice(soffice)、Microsoft Excel 或检查文件。" f" details: {joined}" ) @@ -62,6 +93,7 @@ def _trim_trailing_empty(vals: list[str]) -> list[str]: def run(input_data: dict, context: Context) -> list[dict]: + import os file_path = Path(input_data["file_path"]) work_dir = Path(input_data["work_dir"]) if file_path.suffix.lower() == ".xls": diff --git a/backend/edkb_system/skills/loader_pdf.py b/backend/edkb_system/skills/loader_pdf.py index 36532d94..052c189e 100644 --- a/backend/edkb_system/skills/loader_pdf.py +++ b/backend/edkb_system/skills/loader_pdf.py @@ -16,7 +16,7 @@ _MIN_TEXT_HEAVY_IMAGE_BYTES = 24 * 1024 def _is_scanned(text_chars: int, pages: int) -> bool: - return text_chars < int(300 * max(pages, 1) / 10) + return text_chars < int(150 * max(pages, 1)) def _is_text_heavy_pdf(text_chars: int, pages: int) -> bool: diff --git a/backend/requirements.txt b/backend/requirements.txt index 99abc2e2..8eb50066 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -32,6 +32,7 @@ pypdfium2==5.0.0 python-pptx==1.0.2 beautifulsoup4==4.14.2 lxml==6.0.2 +xlrd==2.0.1 typer==0.17.4 croniter pyyaml From 3f61e92549a02e73df0c502b520103155de19378 Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Fri, 12 Jun 2026 17:04:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/auth/composables/useLoginAuth.ts | 17 +++++- frontend/src/i18n.ts | 24 +++++++++ frontend/src/locales/en/auth.json | 5 +- frontend/src/locales/th/auth.json | 5 +- frontend/src/locales/zh-CN/auth.json | 5 +- frontend/src/locales/zh-TW/auth.json | 5 +- .../shared/components/LevelMessageDialog.vue | 22 +++++--- .../composables/useGlobalMessageDialog.ts | 9 ++++ frontend/src/shared/composables/useMessage.ts | 53 +++++++++++++++---- 9 files changed, 122 insertions(+), 23 deletions(-) diff --git a/frontend/src/features/auth/composables/useLoginAuth.ts b/frontend/src/features/auth/composables/useLoginAuth.ts index 238fdc99..2ebe3c9d 100644 --- a/frontend/src/features/auth/composables/useLoginAuth.ts +++ b/frontend/src/features/auth/composables/useLoginAuth.ts @@ -84,7 +84,17 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) { event?.stopPropagation(); if (!loginUsername.value.trim()) { - msg.warning(t('login.usernameRequired')); + msg.warning({ + title: t('login.usernameRequired'), + message: t('login.usernameRequiredHint'), + }); + return; + } + if (!loginPassword.value) { + msg.warning({ + title: t('login.passwordRequired'), + message: t('login.passwordRequiredHint'), + }); return; } @@ -115,7 +125,10 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) { if (rawError === 'Database connection failed') errorText = t('login.dbConnectionFailed'); if (rawError === 'Internal server error') errorText = t('login.internalError'); console.error(e); - msg.error(errorText || t('login.requestFailed')); + msg.error({ + title: t('login.failed'), + message: errorText || t('login.requestFailed'), + }); } }; diff --git a/frontend/src/i18n.ts b/frontend/src/i18n.ts index feac13d6..304143a2 100644 --- a/frontend/src/i18n.ts +++ b/frontend/src/i18n.ts @@ -17,6 +17,12 @@ const messages = { "defaultMessage": "When clicked the OK button, this dialog will be closed after 1 second", "cancel": "Cancel", "confirm": "OK" + }, + "messageDialog": { + "success": "Success", + "info": "Notice", + "warning": "Warning", + "error": "Error" } }, "scheduleRuns": { @@ -135,6 +141,12 @@ const messages = { "defaultMessage": "点击“确定”按钮后,该对话框将在 1 秒后关闭", "cancel": "取消", "confirm": "确定" + }, + "messageDialog": { + "success": "操作成功", + "info": "提示", + "warning": "警告", + "error": "错误" } }, "scheduleRuns": { @@ -253,6 +265,12 @@ const messages = { "defaultMessage": "點擊「確定」按鈕後,此對話框將在 1 秒後關閉", "cancel": "取消", "confirm": "確定" + }, + "messageDialog": { + "success": "操作成功", + "info": "提示", + "warning": "警告", + "error": "錯誤" } }, "scheduleRuns": { @@ -371,6 +389,12 @@ const messages = { "defaultMessage": "เมื่อกดปุ่มตกลง กล่องโต้ตอบนี้จะปิดหลังจาก 1 วินาที", "cancel": "ยกเลิก", "confirm": "ตกลง" + }, + "messageDialog": { + "success": "สำเร็จ", + "info": "แจ้งเตือน", + "warning": "คำเตือน", + "error": "ข้อผิดพลาด" } }, "scheduleRuns": { diff --git a/frontend/src/locales/en/auth.json b/frontend/src/locales/en/auth.json index 4388a716..e079cbd8 100644 --- a/frontend/src/locales/en/auth.json +++ b/frontend/src/locales/en/auth.json @@ -13,7 +13,10 @@ }, "failed": "Login failed", "inputError": "Please enter username and password", - "usernameRequired": "Please enter username", + "usernameRequired": "Username cannot be empty", + "usernameRequiredHint": "Please enter your username", + "passwordRequired": "Password cannot be empty", + "passwordRequiredHint": "Please enter your password", "loginRequired": "Please login first", "requestFailed": "Login request failed", "forgotPassword": "Forgot Password?", diff --git a/frontend/src/locales/th/auth.json b/frontend/src/locales/th/auth.json index e9ae4197..e8012830 100644 --- a/frontend/src/locales/th/auth.json +++ b/frontend/src/locales/th/auth.json @@ -13,7 +13,10 @@ }, "failed": "การเข้าสู่ระบบล้มเหลว", "inputError": "กรุณากรอกชื่อผู้ใช้และรหัสผ่าน", - "usernameRequired": "กรุณากรอกชื่อผู้ใช้", + "usernameRequired": "ชื่อผู้ใช้ต้องไม่ว่าง", + "usernameRequiredHint": "กรุณากรอกชื่อผู้ใช้", + "passwordRequired": "รหัสผ่านต้องไม่ว่าง", + "passwordRequiredHint": "กรุณากรอกรหัสผ่าน", "loginRequired": "กรุณาเข้าสู่ระบบก่อนเริ่มการสนทนา", "requestFailed": "คำขอเข้าสู่ระบบล้มเหลว", "forgotPassword": "ลืมรหัสผ่าน?", diff --git a/frontend/src/locales/zh-CN/auth.json b/frontend/src/locales/zh-CN/auth.json index 26379f33..019fe169 100644 --- a/frontend/src/locales/zh-CN/auth.json +++ b/frontend/src/locales/zh-CN/auth.json @@ -13,7 +13,10 @@ }, "failed": "登录失败", "inputError": "请输入用户名和密码", - "usernameRequired": "请输入用户名", + "usernameRequired": "用户名不能为空", + "usernameRequiredHint": "请输入用户名", + "passwordRequired": "密码不能为空", + "passwordRequiredHint": "请输入密码", "loginRequired": "请先登录", "requestFailed": "登录请求失败", "forgotPassword": "忘记密码?", diff --git a/frontend/src/locales/zh-TW/auth.json b/frontend/src/locales/zh-TW/auth.json index 70db2cdb..3ae66f71 100644 --- a/frontend/src/locales/zh-TW/auth.json +++ b/frontend/src/locales/zh-TW/auth.json @@ -13,7 +13,10 @@ }, "failed": "登錄失敗", "inputError": "請輸入用戶名和密碼", - "usernameRequired": "請輸入用戶名", + "usernameRequired": "用戶名不能為空", + "usernameRequiredHint": "請輸入用戶名", + "passwordRequired": "密碼不能為空", + "passwordRequiredHint": "請輸入密碼", "loginRequired": "請先登錄後再進入對話", "requestFailed": "登錄請求失敗", "forgotPassword": "忘記密碼?", diff --git a/frontend/src/shared/components/LevelMessageDialog.vue b/frontend/src/shared/components/LevelMessageDialog.vue index c74d1261..706b8e03 100644 --- a/frontend/src/shared/components/LevelMessageDialog.vue +++ b/frontend/src/shared/components/LevelMessageDialog.vue @@ -2,9 +2,12 @@ /** * shared/components/LevelMessageDialog.vue * 全局分级消息弹窗(info/success/warning/error)。 + * 依赖:vue-i18n、lucide-vue-next。 + * 逻辑:App.vue 挂载本组件;useGlobalMessageDialog 驱动 title(顶部摘要)与 message(正文)展示。 */ import { computed, onBeforeUnmount, watch } from 'vue'; +import { useI18n } from 'vue-i18n'; import { Check, Info, AlertTriangle, XCircle, X } from 'lucide-vue-next'; type MessageLevel = 'success' | 'info' | 'warning' | 'error'; @@ -47,16 +50,18 @@ const ICON_MAP: Record = { error: XCircle, }; -const DEFAULT_TITLE_MAP: Record = { - success: 'Success', - info: 'Info', - warning: 'Warning', - error: 'Error', +const { t } = useI18n(); + +const DEFAULT_TITLE_KEY_MAP: Record = { + success: 'common.messageDialog.success', + info: 'common.messageDialog.info', + warning: 'common.messageDialog.warning', + error: 'common.messageDialog.error', }; const panelClass = computed(() => ALERT_CLASS[props.level]); const resolvedIcon = computed(() => ICON_MAP[props.level]); -const resolvedTitle = computed(() => props.title || DEFAULT_TITLE_MAP[props.level]); +const resolvedTitle = computed(() => props.title || t(DEFAULT_TITLE_KEY_MAP[props.level])); const resolvedMessage = computed(() => props.message || ''); let autoCloseTimer: ReturnType | null = null; @@ -139,7 +144,10 @@ onBeforeUnmount(() => {

{{ resolvedTitle }}

-

+

{{ resolvedMessage }}

diff --git a/frontend/src/shared/composables/useGlobalMessageDialog.ts b/frontend/src/shared/composables/useGlobalMessageDialog.ts index 11e6b6b9..d030f927 100644 --- a/frontend/src/shared/composables/useGlobalMessageDialog.ts +++ b/frontend/src/shared/composables/useGlobalMessageDialog.ts @@ -1,6 +1,8 @@ /** * shared/composables/useGlobalMessageDialog.ts * 全局消息弹窗单例状态与展示控制。 + * 依赖:vue ref/readonly。 + * 逻辑:App.vue 绑定本 composable 状态至 LevelMessageDialog;业务层经 useMessage 调用。 */ import { readonly, ref } from 'vue'; @@ -34,6 +36,13 @@ const formatMessageForDialog = (level: MessageLevel, raw: string) => { }; export const useGlobalMessageDialog = () => { + /** + * 打开全局分级消息弹窗。 + * 核心逻辑:写入 level/title/message 单例状态;title 为顶部摘要,message 为正文。 + * @param nextLevel - 消息级别 + * @param nextMessage - 正文内容 + * @param nextTitle - 顶部标题;为空时由 LevelMessageDialog 按级别取 i18n 默认文案 + */ const showMessageDialog = ( nextLevel: MessageLevel, nextMessage: string, diff --git a/frontend/src/shared/composables/useMessage.ts b/frontend/src/shared/composables/useMessage.ts index 9d87f903..bbcf6a63 100644 --- a/frontend/src/shared/composables/useMessage.ts +++ b/frontend/src/shared/composables/useMessage.ts @@ -1,33 +1,66 @@ /** * shared/composables/useMessage.ts * 业务层消息助手,封装全局 LevelMessageDialog 调用。 + * 依赖:useGlobalMessageDialog。 + * 逻辑:各业务 composable 通过本模块弹出 info/success/warning/error 提示。 */ import { useGlobalMessageDialog } from './useGlobalMessageDialog'; -type MessageTitle = string | undefined; +export type MessageTitle = string | undefined; + +/** 顶部标题 + 正文内容的结构化入参 */ +export type MessagePayload = { + title: string; + message: string; +}; + +export type MessageInput = string | MessagePayload; + +/** + * 将字符串或结构化入参统一为 title / message。 + * 核心逻辑:对象形式时 title 为顶部摘要、message 为正文;字符串形式时 message 为正文、title 取第二参数。 + * @param input - 正文或 { title, message } + * @param title - 字符串入参时的可选顶部标题 + * @returns 归一化后的 title 与 message + */ +const resolveMessageInput = (input: MessageInput, title?: MessageTitle) => { + if (typeof input === 'object') { + return { title: input.title, message: input.message }; + } + return { title: title ?? '', message: input }; +}; /** * 业务层消息助手: * - 统一复用全局 LevelMessageDialog - * - 提供更短的方法名,减少重复传 level 字符串 + * - msg.warning({ title: '用户名不能为空', message: '请输入用户名' }):双行 + * - msg.error('用户不存在', '登录失败') 或 msg.error({ title: '登录失败', message: '用户不存在' }) */ export const useMessage = () => { const { showMessageDialog } = useGlobalMessageDialog(); - const info = (message: string, title?: MessageTitle) => - showMessageDialog('info', message, title); + const info = (input: MessageInput, title?: MessageTitle) => { + const resolved = resolveMessageInput(input, title); + showMessageDialog('info', resolved.message, resolved.title); + }; - const success = (message: string, title?: MessageTitle) => - showMessageDialog('success', message, title); + const success = (input: MessageInput, title?: MessageTitle) => { + const resolved = resolveMessageInput(input, title); + showMessageDialog('success', resolved.message, resolved.title); + }; - const warning = (message: string, title?: MessageTitle) => - showMessageDialog('warning', message, title); + const warning = (input: MessageInput, title?: MessageTitle) => { + const resolved = resolveMessageInput(input, title); + showMessageDialog('warning', resolved.message, resolved.title); + }; // 兼容常见缩写调用:msg.warn(...) const warn = warning; - const error = (message: string, title?: MessageTitle) => - showMessageDialog('error', message, title); + const error = (input: MessageInput, title?: MessageTitle) => { + const resolved = resolveMessageInput(input, title); + showMessageDialog('error', resolved.message, resolved.title); + }; return { info, From 587a215d880a004c16e419628e180a1aaaf4e636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9A=E9=80=9A?= Date: Fri, 12 Jun 2026 22:37:46 +0800 Subject: [PATCH 3/4] =?UTF-8?q?docs(agents.md):=E4=BC=98=E5=8C=96=20agent.?= =?UTF-8?q?md=E5=8F=8A=EF=BC=8Ccode-comments.mdc=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=EF=BC=9B=20=E8=A7=84=E5=88=92=E4=B8=89=E5=B1=82=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=EF=BC=88=E6=96=87=E4=BB=B6=E3=80=81=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E3=80=81=E4=BB=A3=E7=A0=81=EF=BC=89=EF=BC=9B=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E4=B8=8D=E4=BB=85=E7=BB=99=E4=BA=BA=E7=9C=8B=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E5=86=99=E7=BB=99=20AI=20=E7=9C=8B=EF=BC=8C=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=86=B3=E5=AE=9A=E5=A4=A7=E6=A8=A1=E5=9E=8B=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=EF=BC=9B=E5=BA=9F=E9=99=A4=E6=97=A0=E6=84=8F=E4=B9=89?= =?UTF-8?q?=E7=9A=84=E9=80=90=E8=A1=8C=E8=AF=AD=E6=B3=95=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E3=80=82=E4=BF=AE=E6=94=B9=E6=8F=90=E7=A4=BA=E8=AF=8D=E6=88=96?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=8F=82=E6=95=B0=E6=97=B6=EF=BC=8C=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E4=BD=BF=E7=94=A8=20[PROMPT=5FUPDATE]=20=E7=AD=89?= =?UTF-8?q?=E4=B8=93=E5=B1=9E=E6=A0=87=E7=AD=BE=E8=AE=B0=E5=BD=95=E2=80=9C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8E=9F=E5=9B=A0=E2=80=9D=EF=BC=8C=E5=91=8A?= =?UTF-8?q?=E5=88=AB=E7=8E=84=E5=AD=A6=E8=B0=83=E5=8F=82=EF=BC=9B=E7=BB=86?= =?UTF-8?q?=E5=88=99=E5=B7=B2=E5=86=99=E5=85=A5=20.cursor/rules=EF=BC=8CAI?= =?UTF-8?q?=20=E5=8A=A9=E6=89=8B=E5=B0=86=E8=87=AA=E5=8A=A8=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=B9=B6=E8=BE=85=E5=8A=A9=E6=89=A7=E8=A1=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursor/rules/code-comments copy.mdc | 70 ++++++++++ .cursor/rules/code-comments.mdc | 74 +++++++--- .gitignore | 2 + AGENTS copy.md | 196 +++++++++++++++++++++++++++ AGENTS.md | 62 ++++----- 5 files changed, 351 insertions(+), 53 deletions(-) create mode 100644 .cursor/rules/code-comments copy.mdc create mode 100644 AGENTS copy.md diff --git a/.cursor/rules/code-comments copy.mdc b/.cursor/rules/code-comments copy.mdc new file mode 100644 index 00000000..ecd5edf3 --- /dev/null +++ b/.cursor/rules/code-comments copy.mdc @@ -0,0 +1,70 @@ +--- +description: 文件层与函数层注释强制规范(撰写与调整代码时均适用) +alwaysApply: true +--- + +# 代码注释(强制) + +撰写或**修改**代码时,必须补齐或更新两层注释。完整说明见 `AGENTS.md` §5。 + +## 文件层(文件顶部) + +块注释须包含:**用途**、**主要 import/依赖**、**与上下游文件的逻辑关系**。 + +```typescript +/** + * features/kb/composables/useKbWorkspace.ts + * 用途:知识库作业面编排入口,组合 state / computed / data 等子模块。 + * 依赖:kb-workspace/* composables、kb.api、kb-display.utils。 + * 逻辑:KbWorkspaceView 调用本 composable;本文件再分发至 useKbWorkspaceData 等子模块。 + */ +``` + +```python +""" +services/kb_sync.py + +用途:知识库文档与 Dify 之间的同步编排。 +依赖:dify_service、models.KbDocument、minio_service。 +逻辑:由 api/knowledge_base 路由调用;内部委托 chunking 与 job 状态机。 +""" +``` + +## 函数层(每个函数定义上方) + +须说明:**用途**、**核心逻辑与实现方式**、**参数**与**返回值**(及异常)。 + +```typescript +/** + * 加载当前分组下的文档列表,并在静默刷新时合并 stable 项避免闪烁。 + * 核心逻辑:调用 getKbGroupFilesSafe,按 mergeStableItems 策略合并新旧列表。 + * @param options.silent - 为 true 时不切换 loading,用于轮询刷新 + * @returns 是否成功拉取到数据 + */ +async function loadDocuments(options?: LoadListOptions): Promise { ... } +``` + +```python +def sync_document_to_dify(document_id: int, *, force: bool = False) -> SyncResult: + """ + 将指定文档切片同步至 Dify 知识库。 + + 核心逻辑:读 MinIO 原文 → 切块 → 调 Dify API upsert;失败写入 KbJob 供重试。 + + Args: + document_id: 本地 KbDocument 主键。 + force: 为 True 时忽略已完成状态强制重同步。 + + Returns: + SyncResult: 含 dify_document_id 与分段数。 + + Raises: + KbNotFoundError: 文档不存在或无权限。 + """ +``` + +## 修改既有文件时 + +- 改函数逻辑/签名 → 同步改该函数注释。 +- 改 import 或模块协作关系 → 同步改文件头注释。 +- Vue SFC:` diff --git a/frontend/src/features/admin/modules/schedules/components/ScheduleCreateEditModal.vue b/frontend/src/features/admin/modules/schedules/components/ScheduleCreateEditModal.vue new file mode 100644 index 00000000..377c6254 --- /dev/null +++ b/frontend/src/features/admin/modules/schedules/components/ScheduleCreateEditModal.vue @@ -0,0 +1,534 @@ + + + diff --git a/frontend/src/features/admin/modules/schedules/components/ScheduleOverviewPanel.vue b/frontend/src/features/admin/modules/schedules/components/ScheduleOverviewPanel.vue new file mode 100644 index 00000000..f9273c50 --- /dev/null +++ b/frontend/src/features/admin/modules/schedules/components/ScheduleOverviewPanel.vue @@ -0,0 +1,149 @@ +/** + * features/admin/modules/schedules/components/ScheduleOverviewPanel.vue + * 定时任务概览模式:统计卡片与任务卡片网格。 + * 依赖:schedules.context、lucide-vue-next。 + * 逻辑:inject admin;展示 schedules 列表与快捷操作。 + */ + + + diff --git a/frontend/src/features/admin/modules/schedules/components/SchedulePageHeader.vue b/frontend/src/features/admin/modules/schedules/components/SchedulePageHeader.vue new file mode 100644 index 00000000..3ea3da8b --- /dev/null +++ b/frontend/src/features/admin/modules/schedules/components/SchedulePageHeader.vue @@ -0,0 +1,46 @@ +/** + * features/admin/modules/schedules/components/SchedulePageHeader.vue + * 定时任务页顶栏:返回、标题、刷新。 + * 依赖:schedules.context、lucide-vue-next。 + * 逻辑:inject admin 上下文;概览/工作台模式切换标题与返回按钮。 + */ + + + diff --git a/frontend/src/features/admin/modules/schedules/components/ScheduleTestRunDialog.vue b/frontend/src/features/admin/modules/schedules/components/ScheduleTestRunDialog.vue new file mode 100644 index 00000000..a46c09c3 --- /dev/null +++ b/frontend/src/features/admin/modules/schedules/components/ScheduleTestRunDialog.vue @@ -0,0 +1,183 @@ + + +