Merge branch 'dev' into prod by super
This commit is contained in:
commit
fbf5537dcd
15 files changed
+485
-105
No files matched your search
+8
-4
@@ -45,7 +45,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install Python dependencies
|
# Install Python dependencies
|
||||||
COPY backend/requirements.txt .
|
COPY backend/requirements.txt backend/requirements-ocr.txt ./
|
||||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
set -eux; \
|
set -eux; \
|
||||||
PIP_ARGS="--no-cache-dir --retries 10 --timeout 60"; \
|
PIP_ARGS="--no-cache-dir --retries 10 --timeout 60"; \
|
||||||
@@ -56,9 +56,13 @@ RUN --mount=type=cache,target=/root/.cache/pip \
|
|||||||
PIP_ARGS="$PIP_ARGS --extra-index-url ${PIP_EXTRA_INDEX_URL}"; \
|
PIP_ARGS="$PIP_ARGS --extra-index-url ${PIP_EXTRA_INDEX_URL}"; \
|
||||||
fi; \
|
fi; \
|
||||||
pip install $PIP_ARGS -r requirements.txt && \
|
pip install $PIP_ARGS -r requirements.txt && \
|
||||||
pip uninstall -y opencv-python && \
|
pip install $PIP_ARGS \
|
||||||
pip install $PIP_ARGS opencv-python-headless && \
|
"$(grep '^opencv-python-headless' requirements-ocr.txt)" && \
|
||||||
python -c "import networkx, openpyxl"
|
pip install $PIP_ARGS --no-deps \
|
||||||
|
"$(grep '^rapidocr-onnxruntime' requirements-ocr.txt)" && \
|
||||||
|
pip install $PIP_ARGS \
|
||||||
|
pyclipper Shapely six onnxruntime && \
|
||||||
|
python -c "import cv2; from rapidocr_onnxruntime import RapidOCR; import networkx, openpyxl"
|
||||||
|
|
||||||
# Copy backend code and the Text2SQL schema required at runtime
|
# Copy backend code and the Text2SQL schema required at runtime
|
||||||
COPY backend/ .
|
COPY backend/ .
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ class Config:
|
|||||||
KB_STORAGE_ROOT = os.getenv('KB_STORAGE_ROOT', str(_BACKEND_DIR / 'data' / 'kb'))
|
KB_STORAGE_ROOT = os.getenv('KB_STORAGE_ROOT', str(_BACKEND_DIR / 'data' / 'kb'))
|
||||||
KB_TASK_EXECUTION_MODE = os.getenv('KB_TASK_EXECUTION_MODE', 'sync').strip().lower()
|
KB_TASK_EXECUTION_MODE = os.getenv('KB_TASK_EXECUTION_MODE', 'sync').strip().lower()
|
||||||
KB_WORKER_POLL_SECONDS = float(os.getenv('KB_WORKER_POLL_SECONDS', '2'))
|
KB_WORKER_POLL_SECONDS = float(os.getenv('KB_WORKER_POLL_SECONDS', '2'))
|
||||||
|
# kb-worker 自动回收长时间 running 的任务(秒),默认 300,应大于单次清洗预期耗时
|
||||||
|
KB_JOB_RUNNING_TIMEOUT_SECONDS = float(os.getenv('KB_JOB_RUNNING_TIMEOUT_SECONDS', '300'))
|
||||||
# 数据库连接池配置
|
# 数据库连接池配置
|
||||||
SQLALCHEMY_ENGINE_OPTIONS = {
|
SQLALCHEMY_ENGINE_OPTIONS = {
|
||||||
'pool_size': 20,
|
'pool_size': 20,
|
||||||
|
|||||||
@@ -1,13 +1,74 @@
|
|||||||
"""
|
"""
|
||||||
backend/app/services/knowledge_cleaning/queue_service.py
|
backend/app/services/knowledge_cleaning/queue_service.py
|
||||||
文件用途:知识库任务调度最小实现
|
文件用途:知识库任务调度最小实现
|
||||||
|
|
||||||
|
补充能力(2026-05):
|
||||||
|
- recover_stale_running_jobs:回收超时仍处于 running 的后台任务,防止单条卡死阻塞 worker;
|
||||||
|
- process_next_kb_job 在取 queued 任务前会先执行一次超时回收。
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import KbJob
|
from app.models import KbDocumentVersion, KbJob
|
||||||
|
|
||||||
|
logger = logging.getLogger('kb-worker')
|
||||||
|
|
||||||
|
|
||||||
|
def recover_stale_running_jobs() -> tuple[int, str]:
|
||||||
|
"""
|
||||||
|
回收长时间停留在 running 的任务,避免单条卡死阻塞 worker 队列。
|
||||||
|
|
||||||
|
阈值读取 KB_JOB_RUNNING_TIMEOUT_SECONDS(默认 300 秒),
|
||||||
|
应大于单次清洗的预期耗时(含多次 soffice 转换)。
|
||||||
|
"""
|
||||||
|
timeout_sec = float(current_app.config.get('KB_JOB_RUNNING_TIMEOUT_SECONDS', 300))
|
||||||
|
cutoff = datetime.utcnow() - timedelta(seconds=timeout_sec)
|
||||||
|
|
||||||
|
stale_jobs = (
|
||||||
|
db.session.query(KbJob)
|
||||||
|
.filter(
|
||||||
|
KbJob.job_type.in_(('path_upload', 'clean', 'sync_dify')),
|
||||||
|
KbJob.status == 'running',
|
||||||
|
KbJob.started_at.isnot(None),
|
||||||
|
KbJob.started_at < cutoff,
|
||||||
|
)
|
||||||
|
.order_by(KbJob.started_at.asc(), KbJob.id.asc())
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
if not stale_jobs:
|
||||||
|
return 0, 'no_stale_jobs'
|
||||||
|
|
||||||
|
now = datetime.utcnow()
|
||||||
|
message = f'任务执行超时(超过 {int(timeout_sec)}s),已自动回收'
|
||||||
|
for job in stale_jobs:
|
||||||
|
job.status = 'failed'
|
||||||
|
job.error_message = message
|
||||||
|
job.message = message
|
||||||
|
job.finished_at = now
|
||||||
|
job.progress = 100
|
||||||
|
|
||||||
|
if not job.document_version_id:
|
||||||
|
continue
|
||||||
|
|
||||||
|
version = db.session.get(KbDocumentVersion, job.document_version_id)
|
||||||
|
if not version:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if job.job_type == 'clean' and version.status in ('processing', 'uploaded'):
|
||||||
|
version.status = 'failed'
|
||||||
|
version.error_message = message
|
||||||
|
elif job.job_type == 'sync_dify' and version.status == 'syncing':
|
||||||
|
version.status = 'ready'
|
||||||
|
version.error_message = message
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
logger.warning('recovered %s stale running kb job(s)', len(stale_jobs))
|
||||||
|
return len(stale_jobs), f'recovered_{len(stale_jobs)}'
|
||||||
|
|
||||||
|
|
||||||
def enqueue_kb_job(job_id: int) -> tuple[bool, str]:
|
def enqueue_kb_job(job_id: int) -> tuple[bool, str]:
|
||||||
@@ -46,6 +107,9 @@ def enqueue_clean_job(job_id: int) -> tuple[bool, str]:
|
|||||||
|
|
||||||
|
|
||||||
def process_next_kb_job() -> tuple[bool, str]:
|
def process_next_kb_job() -> tuple[bool, str]:
|
||||||
|
# 先回收历史卡死的 running 任务,再领取下一条 queued 任务
|
||||||
|
recover_stale_running_jobs()
|
||||||
|
|
||||||
job = (
|
job = (
|
||||||
db.session.query(KbJob)
|
db.session.query(KbJob)
|
||||||
.filter(KbJob.job_type.in_(('path_upload', 'clean')), KbJob.status == 'queued')
|
.filter(KbJob.job_type.in_(('path_upload', 'clean')), KbJob.status == 'queued')
|
||||||
|
|||||||
@@ -325,6 +325,12 @@ def run_path_upload_job(job_id: int) -> tuple[bool, str]:
|
|||||||
return True, 'ok'
|
return True, 'ok'
|
||||||
|
|
||||||
|
|
||||||
|
def _is_clean_timeout_error(exc: Exception) -> bool:
|
||||||
|
"""判断清洗异常是否由 soffice / 子进程超时引起(与 soffice_util 错误文案对齐)。"""
|
||||||
|
message = str(exc).lower()
|
||||||
|
return 'timed out' in message or 'timeout' in message
|
||||||
|
|
||||||
|
|
||||||
def run_clean_job(job_id: int) -> tuple[bool, str]:
|
def run_clean_job(job_id: int) -> tuple[bool, str]:
|
||||||
"""
|
"""
|
||||||
第一版最小清洗任务执行器。
|
第一版最小清洗任务执行器。
|
||||||
@@ -378,6 +384,18 @@ def run_clean_job(job_id: int) -> tuple[bool, str]:
|
|||||||
result = build_clean_result(source_path, target_dir)
|
result = build_clean_result(source_path, target_dir)
|
||||||
job_message = '真实清洗结果已生成'
|
job_message = '真实清洗结果已生成'
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
# soffice 超时等不可恢复错误:直接失败,避免回退占位结果掩盖问题
|
||||||
|
if _is_clean_timeout_error(exc):
|
||||||
|
job.status = 'failed'
|
||||||
|
job.progress = 100
|
||||||
|
job.message = '清洗超时'
|
||||||
|
job.error_message = str(exc)
|
||||||
|
job.finished_at = _utc_now()
|
||||||
|
version.status = 'failed'
|
||||||
|
version.error_message = str(exc)
|
||||||
|
db.session.commit()
|
||||||
|
return False, 'timeout'
|
||||||
|
|
||||||
preview_path = target_dir / f'{_normalized_source_filename(version, source_path)}.preview.txt'
|
preview_path = target_dir / f'{_normalized_source_filename(version, source_path)}.preview.txt'
|
||||||
preview_path.write_text(
|
preview_path.write_text(
|
||||||
'\n'.join([
|
'\n'.join([
|
||||||
|
|||||||
@@ -1,47 +1,35 @@
|
|||||||
|
"""
|
||||||
|
backend/edkb_system/skills/doc_to_pdf.py
|
||||||
|
文件用途:将 Word 文档转换为 PDF,供后续 PDF 解析链路使用
|
||||||
|
|
||||||
|
说明:
|
||||||
|
- Windows 优先走 Word COM(word_bridge);
|
||||||
|
- Linux/容器环境走 LibreOffice,转换超时由 soffice_util 统一控制。
|
||||||
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from edkb_system.contracts import Context
|
from edkb_system.contracts import Context
|
||||||
|
from edkb_system.skills.soffice_util import convert_with_soffice, find_soffice
|
||||||
from edkb_system.skills.word_bridge import convert_with_word
|
from edkb_system.skills.word_bridge import convert_with_word
|
||||||
|
|
||||||
|
|
||||||
def _find_soffice() -> str | None:
|
|
||||||
candidates = [
|
|
||||||
os.environ.get("EDKB_SOFFICE"),
|
|
||||||
r"C:\Program Files\LibreOffice\program\soffice.exe",
|
|
||||||
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
|
|
||||||
"soffice",
|
|
||||||
]
|
|
||||||
for c in candidates:
|
|
||||||
if not c:
|
|
||||||
continue
|
|
||||||
if c == "soffice":
|
|
||||||
return c
|
|
||||||
if Path(c).exists():
|
|
||||||
return c
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _convert_with_word(path: Path, out_dir: Path) -> Path:
|
def _convert_with_word(path: Path, out_dir: Path) -> Path:
|
||||||
output = out_dir / f"{path.stem}.pdf"
|
output = out_dir / f"{path.stem}.pdf"
|
||||||
return convert_with_word(path.resolve(), output.resolve(), 17)
|
return convert_with_word(path.resolve(), output.resolve(), 17)
|
||||||
|
|
||||||
|
|
||||||
def _convert_with_soffice(path: Path, out_dir: Path, soffice: str) -> Path:
|
def _convert_with_soffice(path: Path, out_dir: Path, soffice: str) -> Path:
|
||||||
|
"""通过 soffice 转 PDF;超时抛出 RuntimeError。"""
|
||||||
output = out_dir / f"{path.stem}.pdf"
|
output = out_dir / f"{path.stem}.pdf"
|
||||||
cmd = [
|
proc = convert_with_soffice(
|
||||||
soffice,
|
soffice,
|
||||||
"--headless",
|
convert_to="pdf",
|
||||||
"--convert-to",
|
source_path=path,
|
||||||
"pdf",
|
out_dir=out_dir,
|
||||||
str(path),
|
)
|
||||||
"--outdir",
|
|
||||||
str(out_dir),
|
|
||||||
]
|
|
||||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
stderr = (proc.stderr or "").strip() or "no stderr"
|
stderr = (proc.stderr or "").strip() or "no stderr"
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
@@ -66,7 +54,7 @@ def run(input_data: dict, context: Context) -> dict:
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
errors.append(f"word: {exc}")
|
errors.append(f"word: {exc}")
|
||||||
|
|
||||||
soffice = _find_soffice()
|
soffice = find_soffice()
|
||||||
if soffice:
|
if soffice:
|
||||||
try:
|
try:
|
||||||
pdf = _convert_with_soffice(file_path, out_dir, soffice)
|
pdf = _convert_with_soffice(file_path, out_dir, soffice)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import xml.etree.ElementTree as ET
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from edkb_system.contracts import Block, Context
|
from edkb_system.contracts import Block, Context
|
||||||
|
from edkb_system.skills.soffice_util import convert_with_soffice, soffice_candidates
|
||||||
from edkb_system.skills.word_bridge import convert_with_word
|
from edkb_system.skills.word_bridge import convert_with_word
|
||||||
|
|
||||||
|
|
||||||
@@ -1583,6 +1584,11 @@ def _convert_doc_with_word(path: Path, out_dir: Path) -> Path:
|
|||||||
|
|
||||||
|
|
||||||
def _convert_doc_to_docx(path: Path, out_dir: Path) -> Path:
|
def _convert_doc_to_docx(path: Path, out_dir: Path) -> Path:
|
||||||
|
"""
|
||||||
|
将 .doc 转为 .docx。
|
||||||
|
|
||||||
|
Windows 优先 Word COM;Linux/容器走 soffice_util(带 EDKB_SOFFICE_TIMEOUT_SEC 超时)。
|
||||||
|
"""
|
||||||
out_dir.mkdir(parents=True, exist_ok=True)
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
output = out_dir / f"{path.stem}.docx"
|
output = out_dir / f"{path.stem}.docx"
|
||||||
force_reconvert = str(
|
force_reconvert = str(
|
||||||
@@ -1606,29 +1612,24 @@ def _convert_doc_to_docx(path: Path, out_dir: Path) -> Path:
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
errors.append(f"Word COM conversion failed: {exc}")
|
errors.append(f"Word COM conversion failed: {exc}")
|
||||||
|
|
||||||
soffice_candidates = [
|
# 非 Windows:依次尝试 soffice 候选路径,单次转换受 soffice_util 超时保护
|
||||||
os.environ.get("EDKB_SOFFICE"),
|
soffice_candidates_list = soffice_candidates()
|
||||||
r"C:\Program Files\LibreOffice\program\soffice.exe",
|
for soffice in soffice_candidates_list:
|
||||||
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
|
|
||||||
"soffice",
|
|
||||||
]
|
|
||||||
for soffice in soffice_candidates:
|
|
||||||
if not soffice:
|
if not soffice:
|
||||||
continue
|
continue
|
||||||
cmd = [
|
|
||||||
soffice,
|
|
||||||
"--headless",
|
|
||||||
"--convert-to",
|
|
||||||
"docx",
|
|
||||||
str(path),
|
|
||||||
"--outdir",
|
|
||||||
str(out_dir),
|
|
||||||
]
|
|
||||||
try:
|
try:
|
||||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
proc = convert_with_soffice(
|
||||||
|
soffice,
|
||||||
|
convert_to="docx",
|
||||||
|
source_path=path,
|
||||||
|
out_dir=out_dir,
|
||||||
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
errors.append(f"soffice not found: {soffice}")
|
errors.append(f"soffice not found: {soffice}")
|
||||||
continue
|
continue
|
||||||
|
except RuntimeError as exc:
|
||||||
|
errors.append(str(exc))
|
||||||
|
continue
|
||||||
|
|
||||||
if proc.returncode == 0 and output.exists():
|
if proc.returncode == 0 and output.exists():
|
||||||
return output
|
return output
|
||||||
|
|||||||
@@ -1,44 +1,41 @@
|
|||||||
|
"""
|
||||||
|
backend/edkb_system/skills/loader_excel.py
|
||||||
|
文件用途:加载 Excel 表格为结构化数据
|
||||||
|
|
||||||
|
说明:
|
||||||
|
- .xls 旧格式先经 soffice_util 转为 .xlsx,再走 openpyxl 解析。
|
||||||
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from openpyxl import load_workbook
|
from openpyxl import load_workbook
|
||||||
|
|
||||||
from edkb_system.contracts import Context
|
from edkb_system.contracts import Context
|
||||||
|
from edkb_system.skills.soffice_util import convert_with_soffice, soffice_candidates
|
||||||
|
|
||||||
def _soffice_candidates() -> list[str]:
|
|
||||||
return [
|
|
||||||
os.environ.get("EDKB_SOFFICE", "").strip(),
|
|
||||||
r"C:\Program Files\LibreOffice\program\soffice.exe",
|
|
||||||
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
|
|
||||||
"soffice",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _convert_xls_to_xlsx(path: Path, out_dir: Path) -> Path:
|
def _convert_xls_to_xlsx(path: Path, out_dir: Path) -> Path:
|
||||||
|
"""将 .xls 转为 .xlsx;soffice 调用带超时,见 EDKB_SOFFICE_TIMEOUT_SEC。"""
|
||||||
out_dir.mkdir(parents=True, exist_ok=True)
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
output = out_dir / f"{path.stem}.xlsx"
|
output = out_dir / f"{path.stem}.xlsx"
|
||||||
errors: list[str] = []
|
errors: list[str] = []
|
||||||
for soffice in _soffice_candidates():
|
for soffice in soffice_candidates():
|
||||||
if not soffice:
|
if not soffice:
|
||||||
continue
|
continue
|
||||||
cmd = [
|
|
||||||
soffice,
|
|
||||||
"--headless",
|
|
||||||
"--convert-to",
|
|
||||||
"xlsx",
|
|
||||||
str(path),
|
|
||||||
"--outdir",
|
|
||||||
str(out_dir),
|
|
||||||
]
|
|
||||||
try:
|
try:
|
||||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
proc = convert_with_soffice(
|
||||||
|
soffice,
|
||||||
|
convert_to="xlsx",
|
||||||
|
source_path=path,
|
||||||
|
out_dir=out_dir,
|
||||||
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
errors.append(f"soffice not found: {soffice}")
|
errors.append(f"soffice not found: {soffice}")
|
||||||
continue
|
continue
|
||||||
|
except RuntimeError as exc:
|
||||||
|
errors.append(str(exc))
|
||||||
|
continue
|
||||||
if proc.returncode == 0 and output.exists():
|
if proc.returncode == 0 and output.exists():
|
||||||
return output
|
return output
|
||||||
stderr = (proc.stderr or "").strip()
|
stderr = (proc.stderr or "").strip()
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import base64
|
|||||||
import hashlib
|
import hashlib
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from edkb_system.contracts import Block, Context
|
from edkb_system.contracts import Block, Context
|
||||||
|
from edkb_system.skills.soffice_util import convert_with_soffice
|
||||||
|
|
||||||
|
|
||||||
def _to_data_uri(blob: bytes, content_type: str) -> str:
|
def _to_data_uri(blob: bytes, content_type: str) -> str:
|
||||||
@@ -15,17 +15,14 @@ def _to_data_uri(blob: bytes, content_type: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _convert_ppt_to_pptx(path: Path, out_dir: Path) -> Path:
|
def _convert_ppt_to_pptx(path: Path, out_dir: Path) -> Path:
|
||||||
|
"""将 .ppt 转为 .pptx;soffice 超时由 soffice_util 控制。"""
|
||||||
out_dir.mkdir(parents=True, exist_ok=True)
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
cmd = [
|
proc = convert_with_soffice(
|
||||||
"soffice",
|
"soffice",
|
||||||
"--headless",
|
convert_to="pptx",
|
||||||
"--convert-to",
|
source_path=path,
|
||||||
"pptx",
|
out_dir=out_dir,
|
||||||
str(path),
|
)
|
||||||
"--outdir",
|
|
||||||
str(out_dir),
|
|
||||||
]
|
|
||||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise RuntimeError("Install LibreOffice to convert .ppt to .pptx")
|
raise RuntimeError("Install LibreOffice to convert .ppt to .pptx")
|
||||||
output = out_dir / f"{path.stem}.pptx"
|
output = out_dir / f"{path.stem}.pptx"
|
||||||
@@ -35,20 +32,19 @@ def _convert_ppt_to_pptx(path: Path, out_dir: Path) -> Path:
|
|||||||
|
|
||||||
|
|
||||||
def _convert_presentation_to_pdf(path: Path, out_dir: Path) -> Path | None:
|
def _convert_presentation_to_pdf(path: Path, out_dir: Path) -> Path | None:
|
||||||
|
"""将演示文稿转为 PDF;失败或超时返回 None,由上层选择其它解析路径。"""
|
||||||
out_dir.mkdir(parents=True, exist_ok=True)
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
cmd = [
|
|
||||||
"soffice",
|
|
||||||
"--headless",
|
|
||||||
"--convert-to",
|
|
||||||
"pdf",
|
|
||||||
str(path),
|
|
||||||
"--outdir",
|
|
||||||
str(out_dir),
|
|
||||||
]
|
|
||||||
try:
|
try:
|
||||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
proc = convert_with_soffice(
|
||||||
|
"soffice",
|
||||||
|
convert_to="pdf",
|
||||||
|
source_path=path,
|
||||||
|
out_dir=out_dir,
|
||||||
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
except RuntimeError:
|
||||||
|
return None
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
return None
|
return None
|
||||||
output = out_dir / f"{path.stem}.pdf"
|
output = out_dir / f"{path.stem}.pdf"
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
"""
|
||||||
|
backend/edkb_system/skills/soffice_util.py
|
||||||
|
文件用途:LibreOffice(soffice)转换统一封装
|
||||||
|
|
||||||
|
说明:
|
||||||
|
- 为 loader_docx / doc_to_pdf / loader_excel / loader_pptx 等技能提供带超时的 soffice 调用;
|
||||||
|
- 避免单个 Office 文档转换卡死导致 kb-worker 长期阻塞;
|
||||||
|
- 超时阈值通过环境变量 EDKB_SOFFICE_TIMEOUT_SEC 配置(默认 120 秒)。
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def soffice_timeout_sec() -> int:
|
||||||
|
"""读取 soffice 子进程超时秒数,最小 10 秒。"""
|
||||||
|
raw = str(os.environ.get("EDKB_SOFFICE_TIMEOUT_SEC", "120")).strip()
|
||||||
|
try:
|
||||||
|
value = int(raw)
|
||||||
|
except ValueError:
|
||||||
|
value = 120
|
||||||
|
return max(value, 10)
|
||||||
|
|
||||||
|
|
||||||
|
def soffice_candidates() -> list[str]:
|
||||||
|
"""返回 soffice 可执行文件候选路径(环境变量优先,其次 Windows 默认安装路径)。"""
|
||||||
|
return [
|
||||||
|
os.environ.get("EDKB_SOFFICE", "").strip(),
|
||||||
|
r"C:\Program Files\LibreOffice\program\soffice.exe",
|
||||||
|
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
|
||||||
|
"soffice",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def find_soffice() -> str | None:
|
||||||
|
"""返回第一个可用的 soffice 路径;PATH 中的 `soffice` 不做存在性探测。"""
|
||||||
|
for candidate in soffice_candidates():
|
||||||
|
if not candidate:
|
||||||
|
continue
|
||||||
|
if candidate == "soffice":
|
||||||
|
return candidate
|
||||||
|
if Path(candidate).exists():
|
||||||
|
return candidate
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def run_soffice(cmd: list[str]) -> subprocess.CompletedProcess[str]:
|
||||||
|
"""
|
||||||
|
执行 soffice 命令并强制超时。
|
||||||
|
|
||||||
|
超时时抛出 RuntimeError,供上层清洗任务识别为失败而非无限等待。
|
||||||
|
"""
|
||||||
|
timeout = soffice_timeout_sec()
|
||||||
|
try:
|
||||||
|
return subprocess.run(
|
||||||
|
cmd,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=timeout,
|
||||||
|
)
|
||||||
|
except subprocess.TimeoutExpired as exc:
|
||||||
|
label = Path(cmd[-2]).name if len(cmd) >= 2 else "soffice"
|
||||||
|
raise RuntimeError(
|
||||||
|
f"soffice timed out after {timeout}s: {label}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
|
||||||
|
def convert_with_soffice(
|
||||||
|
soffice: str,
|
||||||
|
*,
|
||||||
|
convert_to: str,
|
||||||
|
source_path: Path,
|
||||||
|
out_dir: Path,
|
||||||
|
) -> subprocess.CompletedProcess[str]:
|
||||||
|
"""
|
||||||
|
以 headless 模式调用 soffice 做格式转换。
|
||||||
|
|
||||||
|
:param convert_to: 目标格式,如 docx / pdf / xlsx / pptx
|
||||||
|
"""
|
||||||
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
cmd = [
|
||||||
|
soffice,
|
||||||
|
"--headless",
|
||||||
|
"--convert-to",
|
||||||
|
convert_to,
|
||||||
|
str(source_path),
|
||||||
|
"--outdir",
|
||||||
|
str(out_dir),
|
||||||
|
]
|
||||||
|
return run_soffice(cmd)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# OCR stack for edkb_system (knowledge-base document image text).
|
||||||
|
# Docker: installed by backend/Dockerfile (headless first, rapidocr --no-deps).
|
||||||
|
# Local dev (avoid downloading opencv-python twice):
|
||||||
|
# pip install -r requirements.txt
|
||||||
|
# pip install "opencv-python-headless>=4.5.1.48,<5"
|
||||||
|
# pip install rapidocr-onnxruntime==1.4.4 --no-deps
|
||||||
|
# pip install pyclipper Shapely six onnxruntime
|
||||||
|
opencv-python-headless>=4.5.1.48,<5
|
||||||
|
rapidocr-onnxruntime==1.4.4
|
||||||
|
pyclipper
|
||||||
|
Shapely
|
||||||
|
six
|
||||||
|
onnxruntime
|
||||||
@@ -23,8 +23,8 @@ pywin32; sys_platform == "win32"
|
|||||||
# File Parsing & edkb_system dependencies from xinxin2
|
# File Parsing & edkb_system dependencies from xinxin2
|
||||||
networkx==3.5
|
networkx==3.5
|
||||||
python-docx==1.2.0
|
python-docx==1.2.0
|
||||||
rapidocr-onnxruntime==1.4.4
|
# OCR stack (opencv + rapidocr) installed via requirements-ocr.txt in Dockerfile
|
||||||
opencv-python-headless
|
# to avoid pip pulling the larger opencv-python wheel as a rapidocr dependency.
|
||||||
pillow==11.3.0
|
pillow==11.3.0
|
||||||
numpy==2.3.3
|
numpy==2.3.3
|
||||||
pypdf==6.1.0
|
pypdf==6.1.0
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
"""
|
||||||
|
backend/tests/test_kb_queue_recovery.py
|
||||||
|
文件用途:知识库任务队列超时回收与 soffice 超时行为测试
|
||||||
|
|
||||||
|
覆盖场景:
|
||||||
|
- recover_stale_running_jobs:回收超时仍处于 running 的 clean 任务;
|
||||||
|
- _is_clean_timeout_error:识别 soffice / 清洗超时错误;
|
||||||
|
- soffice_util.run_soffice:子进程超时后抛出 RuntimeError。
|
||||||
|
"""
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from app import db
|
||||||
|
from app.models import KbDocument, KbDocumentVersion, KbGroup, KbJob, User
|
||||||
|
from app.services.knowledge_cleaning.queue_service import recover_stale_running_jobs
|
||||||
|
from app.services.knowledge_cleaning.tasks import _is_clean_timeout_error
|
||||||
|
from edkb_system.skills import soffice_util
|
||||||
|
|
||||||
|
|
||||||
|
def _configure_app(app, tmp_path):
|
||||||
|
app.config.update(
|
||||||
|
SECRET_KEY='test-secret-key-with-sufficient-length-123456',
|
||||||
|
KB_STORAGE_ROOT=str(tmp_path / 'kb-storage'),
|
||||||
|
KB_JOB_RUNNING_TIMEOUT_SECONDS=60,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _seed_clean_job(*, stale: bool) -> KbJob:
|
||||||
|
user = User(username='kb-queue-user', email='kb-queue@example.com', role='admin', status='active')
|
||||||
|
user.set_password('password123')
|
||||||
|
db.session.add(user)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
|
group = KbGroup(name='queue-test-group', created_by_id=user.id)
|
||||||
|
db.session.add(group)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
|
document = KbDocument(
|
||||||
|
group_id=group.id,
|
||||||
|
title='queue-test-doc.doc',
|
||||||
|
status='uploaded',
|
||||||
|
source_type='upload',
|
||||||
|
created_by_id=user.id,
|
||||||
|
)
|
||||||
|
db.session.add(document)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
|
version = KbDocumentVersion(
|
||||||
|
document_id=document.id,
|
||||||
|
version_no=1,
|
||||||
|
status='processing',
|
||||||
|
is_current=True,
|
||||||
|
source_file_name='queue-test-doc.doc',
|
||||||
|
source_file_path='/tmp/queue-test-doc.doc',
|
||||||
|
uploaded_by_id=user.id,
|
||||||
|
)
|
||||||
|
db.session.add(version)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
|
started_at = datetime.utcnow() - timedelta(seconds=120 if stale else 5)
|
||||||
|
job = KbJob(
|
||||||
|
job_type='clean',
|
||||||
|
status='running',
|
||||||
|
group_id=group.id,
|
||||||
|
document_id=document.id,
|
||||||
|
document_version_id=version.id,
|
||||||
|
progress=20,
|
||||||
|
message='开始执行最小清洗任务',
|
||||||
|
started_at=started_at,
|
||||||
|
created_by_id=user.id,
|
||||||
|
)
|
||||||
|
db.session.add(job)
|
||||||
|
db.session.commit()
|
||||||
|
return job
|
||||||
|
|
||||||
|
|
||||||
|
def test_recover_stale_running_jobs_marks_old_running_job_failed(app, tmp_path):
|
||||||
|
_configure_app(app, tmp_path)
|
||||||
|
with app.app_context():
|
||||||
|
job = _seed_clean_job(stale=True)
|
||||||
|
recovered_count, message = recover_stale_running_jobs()
|
||||||
|
assert recovered_count == 1
|
||||||
|
assert message == 'recovered_1'
|
||||||
|
|
||||||
|
refreshed_job = db.session.get(KbJob, job.id)
|
||||||
|
refreshed_version = db.session.get(KbDocumentVersion, job.document_version_id)
|
||||||
|
assert refreshed_job is not None
|
||||||
|
assert refreshed_job.status == 'failed'
|
||||||
|
assert '自动回收' in (refreshed_job.error_message or '')
|
||||||
|
assert refreshed_version is not None
|
||||||
|
assert refreshed_version.status == 'failed'
|
||||||
|
|
||||||
|
|
||||||
|
def test_recover_stale_running_jobs_ignores_recent_running_job(app, tmp_path):
|
||||||
|
_configure_app(app, tmp_path)
|
||||||
|
with app.app_context():
|
||||||
|
job = _seed_clean_job(stale=False)
|
||||||
|
recovered_count, message = recover_stale_running_jobs()
|
||||||
|
assert recovered_count == 0
|
||||||
|
assert message == 'no_stale_jobs'
|
||||||
|
|
||||||
|
refreshed_job = db.session.get(KbJob, job.id)
|
||||||
|
assert refreshed_job is not None
|
||||||
|
assert refreshed_job.status == 'running'
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_clean_timeout_error_detects_soffice_timeout():
|
||||||
|
assert _is_clean_timeout_error(RuntimeError('soffice timed out after 120s: QP-42.doc'))
|
||||||
|
assert not _is_clean_timeout_error(RuntimeError('edkb_system failed'))
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_soffice_raises_on_timeout(monkeypatch):
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def _raise_timeout(*_args, **_kwargs):
|
||||||
|
raise subprocess.TimeoutExpired(cmd=['soffice'], timeout=120)
|
||||||
|
|
||||||
|
monkeypatch.setattr(soffice_util.subprocess, 'run', _raise_timeout)
|
||||||
|
monkeypatch.setenv('EDKB_SOFFICE_TIMEOUT_SEC', '120')
|
||||||
|
|
||||||
|
with pytest.raises(RuntimeError, match='soffice timed out after 120s'):
|
||||||
|
soffice_util.run_soffice(['soffice', '--headless'])
|
||||||
@@ -43,6 +43,10 @@ services:
|
|||||||
- KB_STORAGE_ROOT=${KB_STORAGE_ROOT:-/app/data/kb}
|
- KB_STORAGE_ROOT=${KB_STORAGE_ROOT:-/app/data/kb}
|
||||||
- KB_TASK_EXECUTION_MODE=${KB_TASK_EXECUTION_MODE:-worker}
|
- KB_TASK_EXECUTION_MODE=${KB_TASK_EXECUTION_MODE:-worker}
|
||||||
- KB_WORKER_POLL_SECONDS=${KB_WORKER_POLL_SECONDS:-2}
|
- KB_WORKER_POLL_SECONDS=${KB_WORKER_POLL_SECONDS:-2}
|
||||||
|
# kb-worker 自动回收长时间 running 的任务(秒)
|
||||||
|
- KB_JOB_RUNNING_TIMEOUT_SECONDS=${KB_JOB_RUNNING_TIMEOUT_SECONDS:-300}
|
||||||
|
# LibreOffice 单次格式转换超时(秒)
|
||||||
|
- EDKB_SOFFICE_TIMEOUT_SEC=${EDKB_SOFFICE_TIMEOUT_SEC:-120}
|
||||||
|
|
||||||
# 允许容器访问宿主机服务 (如数据库)
|
# 允许容器访问宿主机服务 (如数据库)
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
@@ -88,6 +92,10 @@ services:
|
|||||||
- KB_STORAGE_ROOT=${KB_STORAGE_ROOT:-/app/data/kb}
|
- KB_STORAGE_ROOT=${KB_STORAGE_ROOT:-/app/data/kb}
|
||||||
- KB_TASK_EXECUTION_MODE=${KB_TASK_EXECUTION_MODE:-worker}
|
- KB_TASK_EXECUTION_MODE=${KB_TASK_EXECUTION_MODE:-worker}
|
||||||
- KB_WORKER_POLL_SECONDS=${KB_WORKER_POLL_SECONDS:-2}
|
- KB_WORKER_POLL_SECONDS=${KB_WORKER_POLL_SECONDS:-2}
|
||||||
|
# kb-worker 自动回收长时间 running 的任务(秒)
|
||||||
|
- KB_JOB_RUNNING_TIMEOUT_SECONDS=${KB_JOB_RUNNING_TIMEOUT_SECONDS:-300}
|
||||||
|
# LibreOffice 单次格式转换超时(秒)
|
||||||
|
- EDKB_SOFFICE_TIMEOUT_SEC=${EDKB_SOFFICE_TIMEOUT_SEC:-120}
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -44,6 +44,8 @@
|
|||||||
| `KB_STORAGE_ROOT` | 知识库文件根目录 | 容器内建议保持 `/app/data/kb` |
|
| `KB_STORAGE_ROOT` | 知识库文件根目录 | 容器内建议保持 `/app/data/kb` |
|
||||||
| `KB_TASK_EXECUTION_MODE` | 任务执行模式 | 生产建议 `worker` |
|
| `KB_TASK_EXECUTION_MODE` | 任务执行模式 | 生产建议 `worker` |
|
||||||
| `KB_WORKER_POLL_SECONDS` | worker 轮询间隔 | 默认 `2` 即可 |
|
| `KB_WORKER_POLL_SECONDS` | worker 轮询间隔 | 默认 `2` 即可 |
|
||||||
|
| `KB_JOB_RUNNING_TIMEOUT_SECONDS` | running 任务超时回收 | 默认 `300`,应大于单次清洗预期耗时 |
|
||||||
|
| `EDKB_SOFFICE_TIMEOUT_SEC` | LibreOffice 转换超时 | 默认 `120` |
|
||||||
| `INTEGRATION_API_MODE` | 聊天侧集成调用模式 | 主平台自承载时建议 `local` |
|
| `INTEGRATION_API_MODE` | 聊天侧集成调用模式 | 主平台自承载时建议 `local` |
|
||||||
| `WECOM_PUBLIC_BASE_URL` | 对外可访问主平台地址 | 供聊天/企业微信/文件回链生成绝对地址 |
|
| `WECOM_PUBLIC_BASE_URL` | 对外可访问主平台地址 | 供聊天/企业微信/文件回链生成绝对地址 |
|
||||||
| `DIFY_API_BASE` | Dify API 地址 | 按现网环境填写 |
|
| `DIFY_API_BASE` | Dify API 地址 | 按现网环境填写 |
|
||||||
@@ -62,6 +64,7 @@
|
|||||||
- 若当前环境无法访问 Docker Hub,可在执行前设置 `KB_REDIS_IMAGE`,例如改为企业私有仓库中的 Redis 镜像。
|
- 若当前环境无法访问 Docker Hub,可在执行前设置 `KB_REDIS_IMAGE`,例如改为企业私有仓库中的 Redis 镜像。
|
||||||
- 若当前环境无法访问 Docker Hub,也可同时设置 `PYTHON_BASE_IMAGE`、`NODE_BASE_IMAGE`、`NGINX_BASE_IMAGE`,把后端/前端基础镜像切到企业私有仓库。
|
- 若当前环境无法访问 Docker Hub,也可同时设置 `PYTHON_BASE_IMAGE`、`NODE_BASE_IMAGE`、`NGINX_BASE_IMAGE`,把后端/前端基础镜像切到企业私有仓库。
|
||||||
- 若后端 `pip install -r requirements.txt` 速度过慢或不稳定,可设置 `PIP_INDEX_URL` / `PIP_EXTRA_INDEX_URL`。
|
- 若后端 `pip install -r requirements.txt` 速度过慢或不稳定,可设置 `PIP_INDEX_URL` / `PIP_EXTRA_INDEX_URL`。
|
||||||
|
- OCR 依赖(OpenCV/RapidOCR)在 `backend/requirements-ocr.txt`,由 `backend/Dockerfile` 分步安装,避免同时下载 `opencv-python` 与 `opencv-python-headless` 两个大 wheel。
|
||||||
- 若要沿用旧 `xinxin2` 文件目录,切换前需先把历史知识库文件迁入主平台卷,并保证 `KB_STORAGE_ROOT` 指向迁移后的新路径。
|
- 若要沿用旧 `xinxin2` 文件目录,切换前需先把历史知识库文件迁入主平台卷,并保证 `KB_STORAGE_ROOT` 指向迁移后的新路径。
|
||||||
- 若仍要调用外部 integration API,才需要配置 `INTEGRATION_API_BASE` 与 `INTEGRATION_API_KEY`,此时 `INTEGRATION_API_MODE` 设为 `external`。
|
- 若仍要调用外部 integration API,才需要配置 `INTEGRATION_API_BASE` 与 `INTEGRATION_API_KEY`,此时 `INTEGRATION_API_MODE` 设为 `external`。
|
||||||
- 当前知识库主链路的 `worker_kb` 轮询数据库即可工作,`kb-redis` 以 profile 方式保留,用于后续异步队列扩展或外接 Redis 场景。
|
- 当前知识库主链路的 `worker_kb` 轮询数据库即可工作,`kb-redis` 以 profile 方式保留,用于后续异步队列扩展或外接 Redis 场景。
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
import { ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue';
|
import { ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useChat } from '../composables/useChat';
|
import { useChat } from '../composables/useChat';
|
||||||
import { Send, Loader2, Plus, Copy, Edit2, RotateCw, Check, X, PanelLeftClose, PanelLeftOpen, ChevronDown, Sparkles, Database, Mic, LogOut, MessageSquareText, Globe, ExternalLink, Search, LayoutGrid, Briefcase, History, Sun, Moon } from 'lucide-vue-next';
|
import { Send, Loader2, Plus, Copy, Edit2, RotateCw, Check, X, PanelLeftClose, PanelLeftOpen, ChevronDown, Sparkles, Database, Mic, LogOut, MessageSquareText, Globe, ExternalLink, Search, LayoutGrid, Briefcase, History, Sun, Moon, CalendarDays, Building } from 'lucide-vue-next';
|
||||||
import LocaleToggleButton from '../components/LocaleToggleButton.vue';
|
import LocaleToggleButton from '../components/LocaleToggleButton.vue';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
@@ -2127,11 +2127,28 @@ const showChatRating = ref(false);
|
|||||||
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="flex items-center justify-between p-4">
|
<div class="flex items-center justify-between p-4">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-3 w-full min-w-0">
|
||||||
<div class="flex h-8 w-8 items-center justify-center rounded-xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-sm font-bold text-white shadow-sm shadow-brand-500/25">AI</div>
|
<div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-sm font-bold text-white shadow-sm shadow-brand-500/25">
|
||||||
<span class="font-bold text-primary">{{ currentAgent?.name || 'AI' }}</span>
|
{{ currentAgent?.name === '人事规章' ? 'HR' : 'AI' }}
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col justify-center min-w-0 flex-1 relative group">
|
||||||
|
<span class="font-bold text-primary truncate">{{ currentAgent?.name || 'AI' }}</span>
|
||||||
|
<span v-if="currentAgent?.name === '人事规章'" class="block text-[11px] text-muted mt-1 truncate cursor-help">
|
||||||
|
我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。
|
||||||
|
</span>
|
||||||
|
<span v-else-if="currentAgent?.name === '通用入口'" class="block text-[11px] text-muted mt-1 truncate cursor-help">
|
||||||
|
我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<!-- 气泡提示 -->
|
||||||
|
<div v-if="currentAgent?.name === '人事规章' || currentAgent?.name === '通用入口'" class="absolute left-0 top-[calc(100%+0.25rem)] w-[20rem] p-3 bg-surface border border-default rounded-xl opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-[100] shadow-xl pointer-events-none">
|
||||||
|
<div class="leading-relaxed text-[11px] text-secondary">
|
||||||
|
{{ currentAgent?.name === '人事规章' ? '我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。' : '我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button @click="isSidebarCollapsed = true" class="text-muted transition-colors hover:text-secondary">
|
<button @click="isSidebarCollapsed = true" class="text-muted transition-colors hover:text-secondary shrink-0 ml-2">
|
||||||
<PanelLeftClose class="h-5 w-5" />
|
<PanelLeftClose class="h-5 w-5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -2294,11 +2311,65 @@ const showChatRating = ref(false);
|
|||||||
<div
|
<div
|
||||||
:class="messages.length === 0 ? 'h-full' : 'flex min-h-full flex-col justify-end'"
|
:class="messages.length === 0 ? 'h-full' : 'flex min-h-full flex-col justify-end'"
|
||||||
>
|
>
|
||||||
<div v-if="messages.length === 0" class="flex h-full flex-col items-center justify-center py-2 md:pb-16">
|
<div v-if="messages.length === 0" class="flex h-full flex-col items-center justify-center py-2 md:pb-16 w-full px-4">
|
||||||
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
<template v-if="currentAgent?.name === '人事规章'">
|
||||||
AI
|
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
||||||
</div>
|
HR
|
||||||
<h2 class="text-center text-xl font-medium text-primary md:text-2xl">{{ $t('chat.welcomeTitle') }}</h2>
|
</div>
|
||||||
|
<h2 class="text-center text-xl font-bold text-primary md:text-2xl mb-8">你好,我是人事规章 AI 助手</h2>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 w-full max-w-4xl mx-auto">
|
||||||
|
<!-- 考勤与休假 -->
|
||||||
|
<div class="bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm">
|
||||||
|
<div class="flex items-center gap-2 mb-3">
|
||||||
|
<div class="p-1.5 bg-brand-50 rounded-lg text-brand-600">
|
||||||
|
<CalendarDays class="h-4 w-4" />
|
||||||
|
</div>
|
||||||
|
<h3 class="font-semibold text-secondary">考勤与休假</h3>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<button @click="handleSend('查询我有多少假期?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查询我有多少假期?"</button>
|
||||||
|
<button @click="handleSend('如何进行请假?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"如何进行请假?"</button>
|
||||||
|
<button @click="handleSend('查公司法定节假日?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查公司法定节假日?"</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 规章与日常 -->
|
||||||
|
<div class="bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm">
|
||||||
|
<div class="flex items-center gap-2 mb-3">
|
||||||
|
<div class="p-1.5 bg-brand-50 rounded-lg text-brand-600">
|
||||||
|
<Building class="h-4 w-4" />
|
||||||
|
</div>
|
||||||
|
<h3 class="font-semibold text-secondary">规章与日常</h3>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<button @click="handleSend('新员工入职须知')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"新员工入职须知"</button>
|
||||||
|
<button @click="handleSend('怎么开具在职证明?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"怎么开具在职证明?"</button>
|
||||||
|
<button @click="handleSend('查公司薪酬及福利待遇怎么样?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查公司薪酬及福利待遇怎么样?"</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="currentAgent?.name === '通用入口'">
|
||||||
|
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
||||||
|
AI
|
||||||
|
</div>
|
||||||
|
<h2 class="text-center text-xl font-medium text-primary md:text-2xl mb-8">{{ $t('chat.welcomeTitle') }}</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap justify-center gap-3 w-full max-w-3xl mx-auto mt-2">
|
||||||
|
<button @click="handleSend('新员工入职须知')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"新员工入职须知"</button>
|
||||||
|
<button @click="handleSend('查询我有多少假期?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查询我有多少假期?"</button>
|
||||||
|
<button @click="handleSend('如何进行请假?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"如何进行请假?"</button>
|
||||||
|
<button @click="handleSend('查公司法定节假日?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查公司法定节假日?"</button>
|
||||||
|
<button @click="handleSend('查公司薪酬及福利待遇怎么样?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查公司薪酬及福利待遇怎么样?"</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
|
||||||
|
AI
|
||||||
|
</div>
|
||||||
|
<h2 class="text-center text-xl font-medium text-primary md:text-2xl">{{ $t('chat.welcomeTitle') }}</h2>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template v-for="(msg, index) in messages" :key="index">
|
<template v-for="(msg, index) in messages" :key="index">
|
||||||
|
|||||||
Reference in new issue
Block a user