diff --git a/.env.test b/.env.test index 490c2181..b7f38199 100644 --- a/.env.test +++ b/.env.test @@ -35,3 +35,6 @@ CASDOOR_WECOM_PROVIDER_HINT=wecom # Gunicorn配置 GUNICORN_WORKERS=6 + +# 企业微信通知配置(如果不使用企业微信通知,留空即可) +WECOM_NOTIFY_BASE_URL=http://ait.well-trust.com:8890/ \ No newline at end of file diff --git a/.githooks/_common.sh b/.githooks/_common.sh new file mode 100644 index 00000000..731a4a16 --- /dev/null +++ b/.githooks/_common.sh @@ -0,0 +1,45 @@ +# shellcheck shell=bash +# 供 pre-commit / pre-push 引用;勿直接执行。 + +hook_should_skip() { + [[ "${SKIP_GIT_HOOKS:-}" == "1" ]] || [[ "${SKIP_FRONTEND_HOOKS:-}" == "1" ]] +} + +frontend_paths_in() { + local file_list="${1:-}" + echo "${file_list}" | grep -qE '^frontend/' +} + +ensure_frontend_deps() { + local frontend_dir="${1}/frontend" + if [[ ! -d "${frontend_dir}/node_modules" ]]; then + echo "[git-hook] frontend/node_modules 不存在,请先执行:" + echo " cd frontend && npm install" + return 1 + fi + return 0 +} + +run_frontend_typecheck() { + local root_dir="${1}" + echo "[pre-commit] 检测到 frontend/ 变更,运行 vue-tsc 类型检查..." + if ! ensure_frontend_deps "${root_dir}"; then + return 1 + fi + ( + cd "${root_dir}/frontend" + npx vue-tsc -b --pretty false + ) +} + +run_frontend_build() { + local root_dir="${1}" + echo "[pre-push] 检测到将要推送的提交包含 frontend/ 变更,运行 npm run build..." + if ! ensure_frontend_deps "${root_dir}"; then + return 1 + fi + ( + cd "${root_dir}/frontend" + npm run build + ) +} diff --git a/.githooks/pre-commit b/.githooks/pre-commit index f5040541..c5f14568 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -3,6 +3,8 @@ set -euo pipefail ROOT_DIR="$(git rev-parse --show-toplevel)" cd "${ROOT_DIR}" +# shellcheck source=_common.sh +source "${ROOT_DIR}/.githooks/_common.sh" STAGED_FILES="$(git diff --cached --name-only --diff-filter=ACMR || true)" if [[ -z "${STAGED_FILES}" ]]; then @@ -30,4 +32,18 @@ if [[ "${MODELS_CHANGED}" -eq 1 && "${MIGRATION_CHANGED}" -eq 0 ]]; then exit 1 fi +if hook_should_skip; then + exit 0 +fi + +if frontend_paths_in "${STAGED_FILES}"; then + if ! run_frontend_typecheck "${ROOT_DIR}"; then + echo "[pre-commit] vue-tsc 失败,已阻止提交。" + echo "[pre-commit] 跳过前端检查: SKIP_FRONTEND_HOOKS=1 git commit" + echo "[pre-commit] 或跳过全部 hook: git commit --no-verify" + exit 1 + fi + echo "[pre-commit] frontend 类型检查通过。" +fi + exit 0 diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100644 index 00000000..e7fd208d --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(git rev-parse --show-toplevel)" +# shellcheck source=_common.sh +source "${ROOT_DIR}/.githooks/_common.sh" + +if hook_should_skip; then + exit 0 +fi + +zero="0000000000000000000000000000000000000000" +need_frontend_build=0 + +while read -r local_ref local_sha remote_ref remote_sha; do + [[ "${local_sha}" == "${zero}" ]] && continue + + changed_files="" + if [[ "${remote_sha}" == "${zero}" ]]; then + upstream_ref="$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null || true)" + if [[ -n "${upstream_ref}" ]]; then + remote_branch="${upstream_ref#*/}" + remote_name="${upstream_ref%%/*}" + merge_base="$(git merge-base "${local_sha}" "${remote_name}/${remote_branch}" 2>/dev/null || true)" + if [[ -n "${merge_base}" ]]; then + changed_files="$(git diff --name-only --diff-filter=ACMR "${merge_base}" "${local_sha}" || true)" + fi + fi + if [[ -z "${changed_files}" ]]; then + changed_files="$(git diff-tree --no-commit-id --name-only --diff-filter=ACMR -r "${local_sha}" || true)" + fi + else + changed_files="$(git diff --name-only --diff-filter=ACMR "${remote_sha}" "${local_sha}" || true)" + fi + + if frontend_paths_in "${changed_files}"; then + need_frontend_build=1 + break + fi +done + +if [[ "${need_frontend_build}" -eq 0 ]]; then + exit 0 +fi + +if ! run_frontend_build "${ROOT_DIR}"; then + echo "[pre-push] 前端 build 失败,已阻止 push。" + echo "[pre-push] 跳过检查可设置: SKIP_FRONTEND_HOOKS=1 git push" + echo "[pre-push] 或跳过全部 hook: git push --no-verify" + exit 1 +fi + +echo "[pre-push] 前端 build 通过。" +exit 0 diff --git a/Jenkinsfile b/Jenkinsfile index 88ff599b..b11b18e3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -329,6 +329,22 @@ pipeline { } } + // stage('Frontend Build (CI)') { + // when { + // expression { env.FRONTEND_CHANGED == 'true' } + // } + // steps { + // echo '[Frontend Build] FRONTEND_CHANGED=true,容器内执行 npm ci && npm run build(与部署构建一致)' + // sh ''' + // set -e + // docker run --rm \ + // -v "${WORKSPACE}:/repo" \ + // -w /repo \ + // node:22-alpine sh -c "chmod +x scripts/ci_frontend_build.sh && ./scripts/ci_frontend_build.sh" + // ''' + // } + // } + stage('Deploy Dev') { when { expression { diff --git a/backend/app/api/agents.py b/backend/app/api/agents.py index 3805244e..650e1a96 100644 --- a/backend/app/api/agents.py +++ b/backend/app/api/agents.py @@ -20,6 +20,7 @@ def _serialize_agent_row(row) -> dict: 'name': row.name, 'description': row.description, 'icon_url': row.icon_url, + 'dify_app_type': (row.extra_config or {}).get('dify_app_type') if hasattr(row, 'extra_config') else None, } @@ -35,7 +36,7 @@ def list_user_agents(): # 管理员:返回所有激活的 Agent if user.role == 'admin': agent_rows = ( - db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url) + db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url, Agent.extra_config) .filter(Agent.is_active.is_(True)) .order_by(Agent.id.asc()) .all() @@ -48,6 +49,7 @@ def list_user_agents(): 'name': a.name, 'description': a.description, 'icon_url': a.icon_url, + 'extra_config': a.extra_config, })() for a in user.agents if a.is_active @@ -64,7 +66,7 @@ def list_public_agents(): """ # 返回所有激活的 Agent,包含基本信息 agent_rows = ( - db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url) + db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url, Agent.extra_config) .filter(Agent.is_active.is_(True)) .order_by(Agent.id.asc()) .all() diff --git a/backend/app/api/schedule_admin.py b/backend/app/api/schedule_admin.py index 4394e4f9..618f221a 100644 --- a/backend/app/api/schedule_admin.py +++ b/backend/app/api/schedule_admin.py @@ -4,6 +4,9 @@ import threading from datetime import datetime from flask import Blueprint, current_app, jsonify, request, send_file +from flask import Response +from io import BytesIO +import json from app.decorators import require_admin from app import db @@ -24,6 +27,12 @@ from app.services.schedule.srm_service import _fetch_records schedule_admin_bp = Blueprint('schedule_admin', __name__) +def _serialize_task_for_export(task: ScheduleTask, cfg_model: ScheduleTaskConfig | None) -> dict: + payload = serialize_task(task) + payload['config'] = _serialize_task_config(cfg_model) if cfg_model else None + return payload + + def _serialize_task_config(cfg_model: ScheduleTaskConfig) -> dict: return { "row_id_key": cfg_model.row_id_key or "id", @@ -372,6 +381,108 @@ def get_schedules(): return jsonify(list_tasks()) +@schedule_admin_bp.route('/schedules//export', methods=['GET']) +@require_admin +def export_schedule(task_id: int): + task = db.session.get(ScheduleTask, task_id) + if not task: + return jsonify({'error': 'Not found'}), 404 + cfg_model = ScheduleTaskConfig.query.filter_by(schedule_task_id=task_id).first() + payload = { + "schema_version": 1, + "exported_at": datetime.utcnow().isoformat(), + "schedules": [_serialize_task_for_export(task, cfg_model)], + } + body = json.dumps(payload, ensure_ascii=False, indent=2) + filename = f"{(task.schedule_no or f'schedule_{task.id}')}_export_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}.json" + return Response( + body, + mimetype='application/json; charset=utf-8', + headers={'Content-Disposition': f'attachment; filename="{filename}"'}, + ) + + +@schedule_admin_bp.route('/schedules/import', methods=['POST']) +@require_admin +def import_schedules(): + data = request.get_json(silent=True) or {} + schedules = data.get('schedules') + if not isinstance(schedules, list): + return jsonify({'error': 'Invalid import file: schedules missing'}), 400 + + user = get_current_user() + imported = 0 + skipped = 0 + errors: list[str] = [] + + for item in schedules: + if not isinstance(item, dict): + skipped += 1 + continue + try: + name = str(item.get('name') or '').strip() + cron_expr = str(item.get('cron_expr') or '').strip() + owner_user_id = int(item.get('owner_user_id')) + if not name or not cron_expr: + raise ValueError('name or cron_expr missing') + + existing = None + schedule_no = str(item.get('schedule_no') or '').strip() + if schedule_no: + existing = db.session.query(ScheduleTask).filter_by(schedule_no=schedule_no).first() + + task_payload = { + 'name': name, + 'schedule_type': str(item.get('schedule_type') or 'platform_app'), + 'owner_user_id': owner_user_id, + 'cron_expr': cron_expr, + 'wait_seconds': int(item.get('wait_seconds') or 0), + 'dify_agent_id': item.get('dify_agent_id'), + 'platform_api_path': item.get('platform_api_path'), + 'notify_user_ids_json': item.get('notify_user_ids_json') if isinstance(item.get('notify_user_ids_json'), list) else [], + 'notify_enabled': bool(item.get('notify_enabled', True)), + 'enabled': bool(item.get('enabled', True)), + 'data_source_type': str(item.get('data_source_type') or 'database'), + } + cfg = item.get('config') if isinstance(item.get('config'), dict) else None + + if existing: + update_task(existing, payload=task_payload, actor_id=getattr(user, 'id', None)) + existing.data_source_type = task_payload['data_source_type'] + if cfg: + upsert_schedule_task_config(existing.id, cfg) + else: + task = create_task( + name=name, + schedule_type=task_payload['schedule_type'], + owner_user_id=owner_user_id, + cron_expr=cron_expr, + wait_seconds=task_payload['wait_seconds'], + dify_agent_id=task_payload['dify_agent_id'], + platform_api_path=task_payload['platform_api_path'], + notify_user_ids_json=task_payload['notify_user_ids_json'], + notify_enabled=task_payload['notify_enabled'], + enabled=task_payload['enabled'], + actor_id=getattr(user, 'id', None), + ) + task.data_source_type = task_payload['data_source_type'] + db.session.commit() + if cfg: + upsert_schedule_task_config(task.id, cfg) + imported += 1 + except Exception as exc: + errors.append(str(exc)) + skipped += 1 + + db.session.commit() + return jsonify({ + 'ok': True, + 'imported': imported, + 'skipped': skipped, + 'errors': errors[:20], + }) + + @schedule_admin_bp.route('/schedules', methods=['POST']) @require_admin def post_schedule(): diff --git a/backend/app/api/user.py b/backend/app/api/user.py index 99d2f0a6..46b171cd 100644 --- a/backend/app/api/user.py +++ b/backend/app/api/user.py @@ -1887,7 +1887,7 @@ def home(): # Get all agents available to user (including public ones) if user.role == 'admin': agent_rows = ( - db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url) + db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url, Agent.extra_config) .filter(Agent.is_active.is_(True)) .all() ) @@ -1898,6 +1898,7 @@ def home(): 'name': agent.name, 'description': agent.description, 'icon_url': agent.icon_url, + 'extra_config': agent.extra_config, } for agent in user.agents] favorites = db.session.query(UserFavoriteAgent).filter_by(user_id=user.id).all() @@ -1934,7 +1935,12 @@ def home(): 'id': a.id if hasattr(a, 'id') else a['id'], 'name': a.name if hasattr(a, 'name') else a['name'], 'description': a.description if hasattr(a, 'description') else a['description'], - 'icon_url': a.icon_url if hasattr(a, 'icon_url') else a['icon_url'] + 'icon_url': a.icon_url if hasattr(a, 'icon_url') else a['icon_url'], + 'dify_app_type': ( + (a.extra_config or {}).get('dify_app_type') + if hasattr(a, 'extra_config') + else (a.get('extra_config') or {}).get('dify_app_type') + ) or 'chatflow' } for a in agent_rows], 'favorite_agent_ids': favorite_ids, 'quick_questions': [{ diff --git a/backend/app/services/schedule/query_service.py b/backend/app/services/schedule/query_service.py index cbc3324e..58806f75 100644 --- a/backend/app/services/schedule/query_service.py +++ b/backend/app/services/schedule/query_service.py @@ -22,6 +22,7 @@ def serialize_task(task: ScheduleTask, *, last_status: str | None = None) -> dic 'wait_seconds': task.wait_seconds, 'dify_agent_id': task.dify_agent_id, 'platform_api_path': task.platform_api_path, + 'data_source_type': task.data_source_type, 'notify_user_ids_json': task.notify_user_ids_json or [], 'notify_enabled': bool(task.notify_enabled), 'enabled': bool(task.enabled), diff --git a/docs/GIT_HOOKS.md b/docs/GIT_HOOKS.md new file mode 100644 index 00000000..b1bbb961 --- /dev/null +++ b/docs/GIT_HOOKS.md @@ -0,0 +1,221 @@ +# Git Hooks 团队启用指南 + +> 更新时间:2026-05-21 +> 适用对象:全体开发同学 +> 相关脚本:`.githooks/`、`scripts/install_git_hooks.sh`、`scripts/ci_frontend_build.sh` + +团队启用 Git Hook 分两步:**仓库里已有 `.githooks/`(`git pull` 即有)**,**每人本机执行一次安装**。 + +--- + +## 1. 策略概览 + +本地两层 Hook + 远程 Jenkins CI,避免「日常只跑 `npm run dev`、上线 Jenkins `npm run build` 才报错」。 + +| 层级 | 时机 | 谁生效 | 检查内容 | +|------|------|--------|----------| +| **pre-commit** | `git commit` | 已安装 Hook 的本机 | models 须带 migration;暂存 `frontend/` 时跑 `vue-tsc` | +| **pre-push** | `git push` | 已安装 Hook 的本机 | 本次推送含 `frontend/` 变更时跑 `npm run build` | +| **Jenkins CI** | push 触发流水线 | 全员(不装 Hook 也跑) | `npm ci && npm run build`(`scripts/ci_frontend_build.sh`) | + +- Hook **不会**随 `git clone` 自动启用,需每人配置 `core.hooksPath=.githooks`。 +- 没装 Hook 时,主要靠 Jenkins **Frontend Build (CI)** 阶段兜底。 +- 日常开发仍用 `npm run dev`;Hook 只在 commit / push 时额外检查。 + +--- + +## 2. 确认仓库里已有钩子文件 + +在项目根目录(与 `frontend`、`backend` 同级): + +**PowerShell:** + +```powershell +cd D:\path\to\hxops +git pull +dir .githooks +``` + +**Git Bash:** + +```bash +cd /path/to/hxops +git pull +ls -la .githooks +``` + +应能看到: + +- `pre-commit` +- `pre-push` +- `_common.sh` + +若目录不存在,先 `git pull` 到包含这些文件的版本。 + +--- + +## 3. 本机启用(每人、每个 clone 做一次) + +### 3.1 方式 A:安装脚本(推荐) + +在 **Git Bash** 或 **WSL** 中: + +```bash +cd /path/to/hxops +chmod +x scripts/install_git_hooks.sh +./scripts/install_git_hooks.sh +``` + +成功输出示例: + +```text +[hook-install] Installed Git hooks successfully. +[hook-install] pre-commit: models 变更需带 migration;frontend 暂存时跑 vue-tsc +[hook-install] pre-push: 推送含 frontend 变更时跑 npm run build +[hook-install] core.hooksPath=.githooks +``` + +### 3.2 方式 B:PowerShell / CMD + +不跑 bash 脚本时,在仓库根执行: + +```powershell +cd D:\path\to\hxops +git config core.hooksPath .githooks +``` + +若 commit/push 时提示无执行权限,在 Git Bash 中补充: + +```bash +chmod +x .githooks/pre-commit .githooks/pre-push +``` + +### 3.3 方式 C:hxops_menu 菜单 + +在 Git Bash 中运行 `hxops_menu.sh`,选择 **`hook`** 或 **`43`**,确认安装。 + +--- + +## 4. 验证是否生效 + +```powershell +git config --get core.hooksPath +``` + +应输出:`.githooks` + +安装前端依赖(Hook 跑检查前必需): + +```powershell +cd frontend +npm install +``` + +可选自测:暂存一个 `frontend/` 下的小改动后 `git commit`(会触发 `vue-tsc`),测完 `git reset` 即可。 + +--- + +## 5. 装好后会自动做什么 + +### 5.1 pre-commit + +| 条件 | 行为 | +|------|------| +| 暂存了 `backend/app/models.py`,但未暂存 `backend/migrations/versions/*.py` | **拒绝 commit** | +| 暂存路径含 `frontend/` | 运行 `npx vue-tsc -b`(需已有 `node_modules`) | +| 未暂存 `frontend/` | 不跑前端检查 | + +`SKIP_FRONTEND_HOOKS` **不能**跳过 models/migration 检查。 + +### 5.2 pre-push + +| 条件 | 行为 | +|------|------| +| 本次 push 的提交 diff 含 `frontend/` | 运行 `npm run build`(`vue-tsc -b && vite build`) | +| 无 `frontend/` 变更 | 直接通过 | + +### 5.3 Jenkins CI + +- 在 **Detect Changes** 之后、**Deploy** 之前执行。 +- 仅当 `FRONTEND_CHANGED=true` 时在 `node:22-alpine` 容器内执行 `scripts/ci_frontend_build.sh`。 + +--- + +## 6. 团队落地清单(可转发) + +1. **新同事**:`git clone` → `cd frontend && npm install` → 按本文 **§3** 安装 Hook → **§4** 验证。 +2. **老同事**:`git pull` 后若从未装过,补做一次安装。 +3. **换电脑 / 新 clone**:每个新目录都要再装一次(`core.hooksPath` 写在本地 `.git/config`,不随 push 同步)。 +4. **Windows**:建议用 Git for Windows 自带的 Git Bash 执行 commit/push;PowerShell 可用 **§3.2** 仅完成 Hook 路径配置。 + +--- + +## 7. 应急跳过(不要常态化) + +### 7.1 只跳过前端检查 + +migration 规则在 pre-commit 中仍会执行。 + +**Git Bash:** + +```bash +SKIP_FRONTEND_HOOKS=1 git commit -m "your message" +SKIP_FRONTEND_HOOKS=1 git push +``` + +**PowerShell(当前终端会话):** + +```powershell +$env:SKIP_FRONTEND_HOOKS = "1" +git commit -m "your message" +git push +``` + +### 7.2 跳过全部 Hook + +```bash +git commit --no-verify +git push --no-verify +``` + +同时跳过 migration、vue-tsc、build 等所有 Hook。 + +### 7.3 环境变量说明 + +| 变量 | 默认值 | 生效条件 | +|------|--------|----------| +| `SKIP_FRONTEND_HOOKS` | 未设置 | 设为 `1` 时跳过前端 vue-tsc / build | +| `SKIP_GIT_HOOKS` | 未设置 | 设为 `1` 时跳过前端检查(与上一项在前端逻辑等价) | + +仓库内**没有**预置这些变量的配置文件,仅在单次命令前临时设置。 + +--- + +## 8. 常见问题 + +| 现象 | 处理 | +|------|------| +| `dir .githooks` 找不到 | `git pull`;确认在仓库根目录 | +| `missing hook file` | 同上,确保 `.githooks` 已拉取 | +| `frontend/node_modules 不存在` | `cd frontend && npm install` | +| PowerShell 无法执行 `.sh` | 用 **§3.2** 的 `git config`,或改用 Git Bash | +| 装了 Hook 仍不拦截 | 确认 `git config --get core.hooksPath`;是否用了 `--no-verify` | +| 想取消 Hook | `git config --unset core.hooksPath` | + +--- + +## 9. 相关文件 + +| 路径 | 说明 | +|------|------| +| `.githooks/pre-commit` | 提交时检查 | +| `.githooks/pre-push` | 推送时检查 | +| `.githooks/_common.sh` | 共用逻辑 | +| `scripts/install_git_hooks.sh` | 一键安装 | +| `scripts/ci_frontend_build.sh` | Jenkins / 本地 CI 同款 build | +| `Jenkinsfile` | `Frontend Build (CI)` 阶段 | +| `docs/新人环境搭建与配置文档.md` | 新人环境 §4.2 简要说明 | + +--- + +维护建议:调整 Hook 规则或 Jenkins 构建步骤后,请同步更新本文档。 diff --git a/docs/新人环境搭建与配置文档.md b/docs/新人环境搭建与配置文档.md index 18f565eb..ba0cc1be 100644 --- a/docs/新人环境搭建与配置文档.md +++ b/docs/新人环境搭建与配置文档.md @@ -48,6 +48,7 @@ 4. 提交信息建议规范化:`feat:`、`fix:`、`refactor:`、`docs:`、`chore:` 5. 合并前必须完成最少检查: - 能启动前后端 + - 改动了 `frontend/` 时本地 `cd frontend && npm run build` 通过(或已安装 Git Hooks,由 pre-push 自动检查) - 关键页面可访问 - 登录流程可用 6. 任何涉及数据库结构变更的提交,必须包含迁移脚本或升级说明 @@ -62,7 +63,25 @@ git clone https://gitee.com/justop/hxops.git cd hxops ``` -### 4.2 常用 Git 操作示例 +### 4.2 安装 Git Hooks(推荐,每人 clone 后执行一次) + +完整说明见 **[Git Hooks 团队启用指南](./GIT_HOOKS.md)**(策略、安装步骤、验证、跳过方式、常见问题)。 + +快速安装: + +```bash +# Git Bash / WSL +./scripts/install_git_hooks.sh +``` + +```powershell +# PowerShell +git config core.hooksPath .githooks +``` + +验证:`git config --get core.hooksPath` → `.githooks`;前置:`cd frontend && npm install`。 + +### 4.3 常用 Git 操作示例 ```bash # 拉取远程分支 @@ -81,7 +100,7 @@ git commit -m "feat: your change summary" git push origin feature/your-feature-name ``` -### 4.3 关键目录 +### 4.4 关键目录 - `frontend/`:Vue 3 + TypeScript + Vite - `backend/`:Flask + SQLAlchemy + Flask-Migrate diff --git a/frontend/dist/index.html b/frontend/dist/index.html deleted file mode 100644 index 37024f90..00000000 --- a/frontend/dist/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - AI工作台 - - - - -
- - diff --git a/frontend/src/api/schedule.ts b/frontend/src/api/schedule.ts index a3c10c29..28295ea6 100644 --- a/frontend/src/api/schedule.ts +++ b/frontend/src/api/schedule.ts @@ -68,6 +68,21 @@ async function getJson(url: string): Promise { export const listAdminSchedules = () => getJson('/api/admin/schedules'); +export const exportAdminScheduleUrl = (taskId: number) => `/api/admin/schedules/${taskId}/export`; + +export const importAdminSchedules = async (payload: any) => { + const res = await fetch('/api/admin/schedules/import', { + method: 'POST', + headers: { 'Content-Type': 'application/json', ...getAuthHeaders() }, + body: JSON.stringify(payload), + }); + if (!res.ok) { + const data = await res.json().catch(() => ({})); + throw new Error(data.error || 'Import failed'); + } + return res.json(); +}; + export const getAdminScheduleTaskConfig = (taskId: number) => getJson<{ data_source_type: string; config: Record | null }>(`/api/admin/schedule-config/${taskId}`); diff --git a/frontend/src/components/kb/KbAdminPanel.vue b/frontend/src/components/kb/KbAdminPanel.vue new file mode 100644 index 00000000..677d059a --- /dev/null +++ b/frontend/src/components/kb/KbAdminPanel.vue @@ -0,0 +1,354 @@ + + +