zhaoqingang
2025-02-13 25bf0a51088fa0d0acdc39c6096cc45d699f63a1
merge master
1个文件已添加
12个文件已修改
545 ■■■■■ 已修改文件
app/api/agent.py 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/auth.py 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/chat.py 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/files.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/config/env_conf/admin.yaml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/config/env_conf/menu_conf.json 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/config/env_conf/resource.json 376 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/init_config/init_run_data.py 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/models/session_model.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/service/difyService.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/service/ragflow.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/service/session.py 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/service/v2/initialize_data.py 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/agent.py
@@ -233,6 +233,7 @@
                    tmp_data["question"] = i.get("content")
                elif i.get("role") == "assistant":
                    if isinstance(i.get("content"), dict):
                        content = i.get("content", {})
                        tmp_data["answer"] = i.get("content", {}).get("answer")
                        if "file_name" in i.get("content", {}):
                            tmp_data["files"] = [{"file_name": i.get("content", {}).get("file_name"),
@@ -242,6 +243,36 @@
                        if "download_url" in i.get("content", {}):
                            tmp_data["download_url"] = i.get("content", {}).get("download_url")
                        if "node_list" in content:
                            node_dict = {
                                "node_data": [],
                                # {"title": "去除冗余",  # 节点名称 "status": "succeeded",  # 节点状态"created_at": 1735817337,  # 开始时间"finished_at": 1735817337,  # 结束时间"error": ""  # 错误日志}
                                "total_tokens": 0,  # 花费token数
                                "created_at": 0,  # 开始时间
                                "finished_at": 0,  # 结束时间
                                "elapsed_time": 0,  # 结束时间
                                "status": "succeeded",  # 工作流状态
                                "error": "",  # 错误日志
                            }
                            for node in content["node_list"]:
                                if node.get("event") == "node_finished":
                                    node_dict["node_data"].append({
                                        "title": node.get("data", {}).get("title", ""),
                                        "status": node.get("data", {}).get("status", ""),
                                        "created_at": node.get("data", {}).get("created_at", 0),
                                        "finished_at": node.get("data", {}).get("finished_at", 0),
                                        "node_type": node.get("data", {}).get("node_type", 0),
                                        "elapsed_time": node.get("data", {}).get("elapsed_time", 0),
                                        "error": node.get("data", {}).get("error", ""),
                                    })
                                elif node.get("event") == "workflow_finished":
                                    node_dict["total_tokens"] = node.get("data", {}).get("total_tokens", 0)
                                    node_dict["created_at"] = node.get("data", {}).get("created_at", 0)
                                    node_dict["finished_at"] = node.get("data", {}).get("finished_at", 0)
                                    node_dict["status"] = node.get("data", {}).get("status", "")
                                    node_dict["error"] = node.get("data", {}).get("error", "")
                                    node_dict["elapsed_time"] = node.get("data", {}).get("elapsed_time", 0)
                            tmp_data["workflow"] = node_dict
                    else:
                        tmp_data["answer"] = i.get("content")
                    data.append(tmp_data)
app/api/auth.py
@@ -126,14 +126,16 @@
            continue
        try:
            name = login_data.username
            email = ""
            app_password = login_data.password
            user_app = await UserAppDao(db).get_data_by_id(user.id, app["id"])
            if user_app:
                name  = user_app.username
                email  = user_app.email
                app_password = user_app.decrypted_password(user_app.password)
            else:
                await update_user_info(db, user.id)
            token = await service.login(name, app_password)
            token = await service.login(name, app_password,email=email)
            token_dict[app["id"]] = token
        except Exception as e:
            return Response(code=500, msg=f"Failed to login with {app['id']}: {str(e)}")
app/api/chat.py
@@ -1,6 +1,5 @@
import json
import re
import uuid
from copy import deepcopy
from fastapi import WebSocket, WebSocketDisconnect, APIRouter, Depends
@@ -231,7 +230,8 @@
                        question,
                        agent_id,
                        AgentType.BASIC,
                        current_user.id
                        current_user.id,
                        {"role": "user", "content": question}
                    )
                except Exception as e:
                    logger.error(e)
@@ -345,7 +345,8 @@
                                question,
                                agent_id,
                                AgentType.DIFY,
                                current_user.id
                                current_user.id,
                                {"role": "user", "content": question}
                            )
                            conversation_id = session.conversation_id
                        except Exception as e:
@@ -806,7 +807,7 @@
                                        result = {"message": f"内部错误: {e2}", "type": "close"}
                                        await websocket.send_json(result)
                                        print(f"Error process message of ragflow: {e2}")
                elif agent.type == "documentIa":
                elif chat_type == "documentIa":
                    token = DfTokenDao(db).get_token_by_id(DOCUMENT_IA_QUESTIONS)
                    # print(token)
                    if not token:
@@ -828,7 +829,8 @@
                                question,
                                agent_id,
                                AgentType.DIFY,
                                current_user.id
                                current_user.id,
                                {"role": "user", "content": question}
                            )
                            conversation_id = session.conversation_id
                        except Exception as e:
@@ -929,7 +931,6 @@
                                result = {"message": f"内部错误: {e2}", "type": "close"}
                                await websocket.send_json(result)
                                print(f"Error process message of ragflow: {e2}")
            # 启动任务处理客户端消息
            tasks = [
app/api/files.py
@@ -118,7 +118,7 @@
                raise HTTPException(status_code=500, detail=str(e))
        elif agent.chat_type == "reportWorkflow" or agent.chat_type == "documentIa" or agent.chat_type == "paperTalk":
            token_dict = {
                "reportWorkflow": DOCUMENT_TO_REPORT,
                "reportWorkflow": DOCUMENT_TO_REPORT_TITLE,
                "documentIa": DOCUMENT_IA_QUESTIONS,
                "paperTalk": DOCUMENT_TO_PAPER,
            }
app/config/env_conf/admin.yaml
New file
@@ -0,0 +1,12 @@
smart_server:
  account: administer
  password: basic@2025
ragflow_app:
  id: 2c039666c29d11efa4670242ac1b0006
  account: admin@example.com
  password: basic@2025
dify_app:
  account: admin@mail.com
  password: basic@2025
app/config/env_conf/menu_conf.json
@@ -1,23 +1,6 @@
{
  "data": [
    {
      "id": 10,
      "title": "报告生成",
      "icon": "2",
      "img": "/src/assets/index/2.png",
      "desc": "基于您创建的报告格式和知识库中的文档内容,快速生成定制报告,并支持一键下载。",
      "describe": "基于您创建的报告格式和知识库中的文档内容,快速生成定制报告,并支持一键下载。",
      "rank": 100,
      "dialog": [
        {
          "id": "80ee430a-e396-48c4-a12c-7c7cdf5eda51",
          "chat_id": "80ee430a-e396-48c4-a12c-7c7cdf5eda51",
          "chat_type": "report",
          "agentType": 2
        }
      ]
    },
    {
      "id": 1,
      "title": "报表合并",
      "icon": "6",
@@ -155,7 +138,7 @@
    },
    {
      "id": 9,
      "title": "文档报告",
      "title": "报告生成",
      "icon": "2",
      "img": "/src/assets/index/2.png",
      "desc": "基于您创建的报告格式和上传的文档内容,快速生成定制报告,并支持一键下载。",
@@ -163,13 +146,19 @@
      "rank": 91,
      "dialog": [
        {
          "id": "72a69e47-458d-47f9-b534-1859e5da244f",
          "id": "87b8e17c-594d-424f-b9f8-0b56036904c9",
          "chat_id": "basic_report_clean",
          "chat_type": "reportWorkflow",
          "agentType": 4
        },
        {
          "id": "6eda0700-6273-488d-a97c-88d315bd9d8f",
          "id": "61d26deb-9371-4f9c-b61b-b9f9a24a9188",
          "chat_id": "basic_report_clean",
          "chat_type": "reportWorkflow",
          "agentType": 4
        },
        {
          "id": "d6eea92d-444a-4658-b9e7-9ab7bd5cb19d",
          "chat_id": "basic_report_clean",
          "chat_type": "reportWorkflow",
          "agentType": 4
app/config/env_conf/resource.json
@@ -1,8 +1,8 @@
[
  {
    "id": "1eed48e2-d510-42f2-9495-bc299bae237b",
    "created_at": "8/8/2024 19:21:42",
    "updated_at": "8/8/2024 19:21:42",
    "created_at": "26/12/2024 18:45:57",
    "updated_at": "26/12/2024 18:45:57",
    "name": "root",
    "url": "root",
    "path": null,
@@ -15,14 +15,14 @@
    "resource_type_id": "3",
    "resource_id": null,
    "status": "1",
    "hidden": null,
    "hidden": 0,
    "children": [
      {
        "id": "76e81844-c3a6-4ea0-882f-150be2987d9d",
        "created_at": "23/12/2024 09:50:31",
        "updated_at": "23/12/2024 09:50:31",
        "id": "8eadbabd-cf55-469b-ad74-4f9fc80631a1",
        "created_at": "10/1/2025 18:48:05",
        "updated_at": "10/1/2025 18:48:05",
        "name": "智能体详情",
        "url": "/intelligent/detail",
        "url": "DifyDetail",
        "path": "/intelligent/detail",
        "perms": "system:intelligent:detail",
        "description": "",
@@ -32,14 +32,31 @@
        "canbdeeleted": null,
        "resource_type_id": "3",
        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
        "status": "2",
        "status": "1",
        "hidden": 0
      },
      {
        "id": "21e90633-bb76-4419-8925-c20b9ccd33f1",
        "created_at": "10/1/2025 18:48:05",
        "updated_at": "10/1/2025 18:48:05",
        "name": "知识库详情",
        "url": "KnowledgeDetail",
        "path": "/knowledge/detail",
        "perms": "system:knowledge:detail",
        "description": "",
        "icon": "",
        "seq": 0,
        "target": null,
        "canbdeeleted": null,
        "resource_type_id": "3",
        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
        "status": "1",
        "hidden": 0
      },
      {
        "id": "3750795c-404b-488b-8080-89c037b4a187",
        "created_at": "18/12/2024 19:20:09",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "小数",
        "url": "Xiaoshu",
        "path": "/xiaoshu",
@@ -56,8 +73,8 @@
      },
      {
        "id": "3ea0f0b8-5160-4005-91d6-7c6650a5934c",
        "created_at": "20/12/2024 11:38:54",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "会话历史",
        "url": "ConversationHistory",
        "path": "/chat/history",
@@ -74,8 +91,8 @@
      },
      {
        "id": "6469b565-908a-4771-a9e3-1cf8651b26f4",
        "created_at": "12/9/2024 08:01:13",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "会话",
        "url": "ConversationQA",
        "path": "/chat/qa",
@@ -88,12 +105,12 @@
        "resource_type_id": "0",
        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
        "status": "1",
        "hidden": null
        "hidden": 0
      },
      {
        "id": "6b3640d2-6142-4dce-b09b-ce11f9e6c89c",
        "created_at": "20/12/2024 11:38:54",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "会话进行中",
        "url": "ConversationQA",
        "path": "/chat/qa",
@@ -110,8 +127,8 @@
      },
      {
        "id": "6da7445a-5980-4380-ab1d-75021c1dd269",
        "created_at": "18/12/2024 19:20:09",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "智能体",
        "url": "Intelligent",
        "path": "/intelligent",
@@ -127,9 +144,27 @@
        "hidden": 0
      },
      {
        "id": "a4931c80-c890-4142-a698-87940c937b57",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "会话面板",
        "url": "ConversationBoard",
        "path": "/chat/board",
        "perms": "system:conversation:board",
        "description": "",
        "icon": "",
        "seq": 0,
        "target": null,
        "canbdeeleted": null,
        "resource_type_id": "3",
        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
        "status": "1",
        "hidden": 0
      },
      {
        "id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
        "created_at": "18/12/2024 19:20:09",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "知识库管理",
        "url": "Knowledge",
        "path": "/knowledge",
@@ -145,27 +180,9 @@
        "hidden": 0,
        "children": [
          {
            "id": "2d1c2831-79f4-4817-b79f-be4e49687bd1",
            "created_at": "19/12/2024 10:08:40",
            "updated_at": "24/12/2024 19:15:20",
            "name": "知识库详情",
            "url": "KnowledgeDetail",
            "path": "detail",
            "perms": "system:knowledge:detail",
            "description": "",
            "icon": "",
            "seq": 0,
            "target": null,
            "canbdeeleted": null,
            "resource_type_id": "3",
            "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
            "status": "1",
            "hidden": 0
          },
          {
            "id": "242060f6-741e-423a-8634-2f7ece1f0c6d",
            "created_at": "19/12/2024 10:08:40",
            "updated_at": "24/12/2024 19:15:20",
            "created_at": "26/12/2024 18:45:57",
            "updated_at": "26/12/2024 18:45:57",
            "name": "知识库删除",
            "url": "-",
            "path": "-",
@@ -182,8 +199,8 @@
          },
          {
            "id": "25722c9e-63fe-4c80-8c05-5fcb9fb58d01",
            "created_at": "19/12/2024 10:08:40",
            "updated_at": "24/12/2024 19:15:20",
            "created_at": "26/12/2024 18:45:57",
            "updated_at": "26/12/2024 18:45:57",
            "name": "知识库新增",
            "url": "-",
            "path": "-",
@@ -197,31 +214,31 @@
            "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
            "status": "0",
            "hidden": 0
          },
          {
            "id": "91be8704-d6ac-4941-ab9b-02ebfd9c56a3",
            "created_at": "10/1/2025 17:51:51",
            "updated_at": "10/1/2025 18:48:05",
            "name": "文档上传",
            "url": "-",
            "path": "-",
            "perms": "system:knowledgeLib:upload",
            "description": "",
            "icon": "",
            "seq": 0,
            "target": null,
            "canbdeeleted": null,
            "resource_type_id": "1",
            "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
            "status": "1",
            "hidden": 0
          }
        ]
      },
      {
        "id": "a4931c80-c890-4142-a698-87940c937b57",
        "created_at": "20/12/2024 11:38:54",
        "updated_at": "20/12/2024 11:38:54",
        "name": "会话面板",
        "url": "ConversationBoard",
        "path": "/chat/board",
        "perms": "system:conversation:board",
        "description": "",
        "icon": "",
        "seq": 0,
        "target": null,
        "canbdeeleted": null,
        "resource_type_id": "3",
        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
        "status": "1",
        "hidden": 0
      },
      {
        "id": "online",
        "created_at": "25/8/2015 10:34:53",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "模型管理",
        "url": "Model",
        "path": "/model",
@@ -234,12 +251,12 @@
        "resource_type_id": "0",
        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
        "status": "1",
        "hidden": null
        "hidden": 0
      },
      {
        "id": "xtgl",
        "created_at": "25/8/2015 10:34:53",
        "updated_at": "20/12/2024 11:38:54",
        "created_at": "26/12/2024 18:45:57",
        "updated_at": "26/12/2024 18:45:57",
        "name": "权限管理",
        "url": "layout/LayoutPermission",
        "path": "/permission",
@@ -252,12 +269,12 @@
        "resource_type_id": "0",
        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
        "status": "1",
        "hidden": null,
        "hidden": 0,
        "children": [
          {
            "id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
            "created_at": "28/10/2024 07:38:41",
            "updated_at": "18/12/2024 20:05:23",
            "created_at": "26/12/2024 18:45:57",
            "updated_at": "26/12/2024 18:45:57",
            "name": "用户组管理",
            "url": "PermissionGroup",
            "path": "/permission/group",
@@ -270,12 +287,12 @@
            "resource_type_id": "0",
            "resource_id": "xtgl",
            "status": "1",
            "hidden": null,
            "hidden": 0,
            "children": [
              {
                "id": "0bcb1f37-f87e-4f47-ba72-a2e194884b8f",
                "created_at": "28/10/2024 07:41:16",
                "updated_at": "18/12/2024 15:09:28",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "编辑用户组",
                "url": "/base/syuser!update",
                "path": "",
@@ -288,13 +305,12 @@
                "resource_type_id": "1",
                "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "2648f4bd-b5d5-4a34-8b9c-128fd970b014",
                "created_at": "18/12/2024 15:09:28",
                "updated_at": "18/12/2024 15:09:28",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "用户组成员管理",
                "url": "-",
                "path": "",
@@ -309,11 +325,10 @@
                "status": "1",
                "hidden": 0
              },
              {
                "id": "3daf1a03-c0c9-4ebd-935d-fe46561971fb",
                "created_at": "28/10/2024 07:46:14",
                "updated_at": "28/10/2024 07:46:41",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "用户组列表",
                "url": "/base/syuser!grid",
                "path": null,
@@ -326,32 +341,12 @@
                "resource_type_id": "1",
                "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                "status": "1",
                "hidden": null
              },
              {
                "id": "72fe917f-70ee-4cbf-8c21-f1852f3ef037",
                "created_at": "18/12/2024 15:09:28",
                "updated_at": "19/12/2024 16:08:38",
                "name": "用户组权限管理",
                "url": "-",
                "path": "",
                "perms": "system:group:permissionConfig",
                "description": "",
                "icon": "",
                "seq": 0,
                "target": null,
                "canbdeeleted": null,
                "resource_type_id": "1",
                "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                "status": "1",
                "hidden": 0
              },
              {
                "id": "5d9ab44e-488c-4dd8-8688-56650393fab1",
                "created_at": "18/12/2024 11:35:02",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "删除用户组",
                "url": "-",
                "path": "",
@@ -366,11 +361,28 @@
                "status": "1",
                "hidden": 0
              },
              {
                "id": "72fe917f-70ee-4cbf-8c21-f1852f3ef037",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "10/1/2025 18:48:05",
                "name": "用户组权限管理",
                "url": "-",
                "path": "-",
                "perms": "system:group:permissionConfig",
                "description": "",
                "icon": "",
                "seq": 0,
                "target": null,
                "canbdeeleted": null,
                "resource_type_id": "1",
                "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                "status": "1",
                "hidden": 0
              },
              {
                "id": "f2b2c9be-1c39-4416-b3c7-21891fc28f84",
                "created_at": "28/10/2024 07:56:04",
                "updated_at": "28/10/2024 07:56:04",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "添加用户组",
                "url": "/base/sygroup!save",
                "path": null,
@@ -383,14 +395,14 @@
                "resource_type_id": "1",
                "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                "status": "1",
                "hidden": null
                "hidden": 0
              }
            ]
          },
          {
            "id": "jggl",
            "created_at": "25/8/2015 10:34:53",
            "updated_at": "18/12/2024 20:05:23",
            "created_at": "26/12/2024 18:45:57",
            "updated_at": "26/12/2024 18:45:57",
            "name": "机构管理",
            "url": "PermissionOrganization",
            "path": "/permission/org",
@@ -403,12 +415,12 @@
            "resource_type_id": "0",
            "resource_id": "xtgl",
            "status": "1",
            "hidden": null,
            "hidden": 0,
            "children": [
              {
                "id": "jgbj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/5/2022 00:39:56",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "编辑机构",
                "url": "/base/syorganization!update",
                "path": null,
@@ -421,12 +433,12 @@
                "resource_type_id": "1",
                "resource_id": "jggl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "jglb",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "28/11/2016 14:09:52",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "机构列表",
                "url": "/base/syorganization!treeGrid",
                "path": null,
@@ -439,12 +451,12 @@
                "resource_type_id": "1",
                "resource_id": "jggl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "jgsc",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "删除机构",
                "url": "/base/syorganization!delete",
                "path": "",
@@ -457,12 +469,12 @@
                "resource_type_id": "1",
                "resource_id": "jggl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "jgtj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "添加机构",
                "url": "/base/syorganization!save",
                "path": null,
@@ -475,14 +487,14 @@
                "resource_type_id": "1",
                "resource_id": "jggl",
                "status": "1",
                "hidden": null
                "hidden": 0
              }
            ]
          },
          {
            "id": "jsgl",
            "created_at": "25/8/2015 10:34:53",
            "updated_at": "18/12/2024 20:05:23",
            "created_at": "26/12/2024 18:45:57",
            "updated_at": "26/12/2024 18:45:57",
            "name": "角色管理",
            "url": "PermissionRole",
            "path": "/permission/role",
@@ -495,12 +507,12 @@
            "resource_type_id": "0",
            "resource_id": "xtgl",
            "status": "1",
            "hidden": null,
            "hidden": 0,
            "children": [
              {
                "id": "00b61433-a5cd-46e9-a867-2e249dd310f4",
                "created_at": "18/12/2024 11:35:02",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "角色权限配置",
                "url": "-",
                "path": "",
@@ -517,8 +529,8 @@
              },
              {
                "id": "f9947112-c8e4-42cd-ba3a-2612eb373564",
                "created_at": "18/12/2024 11:35:02",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "角色部门配置",
                "url": "-",
                "path": "",
@@ -535,8 +547,8 @@
              },
              {
                "id": "jsbj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "编辑角色",
                "url": "/base/syrole!update",
                "path": null,
@@ -549,12 +561,12 @@
                "resource_type_id": "1",
                "resource_id": "jsgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "jslb",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "角色列表",
                "url": "/base/syrole!grid",
                "path": null,
@@ -567,12 +579,12 @@
                "resource_type_id": "1",
                "resource_id": "jsgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "jssc",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "删除角色",
                "url": "/base/syrole!delete",
                "path": "",
@@ -585,12 +597,12 @@
                "resource_type_id": "1",
                "resource_id": "jsgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "jstj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "添加角色",
                "url": "/base/syrole!save",
                "path": null,
@@ -603,15 +615,14 @@
                "resource_type_id": "1",
                "resource_id": "jsgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              }
            ]
          },
          {
            "id": "yhgl",
            "created_at": "25/8/2015 10:34:53",
            "updated_at": "18/12/2024 20:05:23",
            "created_at": "26/12/2024 18:45:57",
            "updated_at": "26/12/2024 18:45:57",
            "name": "用户管理",
            "url": "PermissionAccount",
            "path": "/permission/account",
@@ -624,12 +635,12 @@
            "resource_type_id": "0",
            "resource_id": "xtgl",
            "status": "1",
            "hidden": null,
            "hidden": 0,
            "children": [
              {
                "id": "07417a54-4afc-45ec-84ee-c59baf7d45b4",
                "created_at": "18/12/2024 11:35:02",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "用户角色",
                "url": "-",
                "path": "",
@@ -644,11 +655,10 @@
                "status": "1",
                "hidden": 0
              },
              {
                "id": "a06316f1-b7e4-48b8-80c8-49b1dbb79c4a",
                "created_at": "18/12/2024 11:35:02",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "重制密码",
                "url": "-",
                "path": "",
@@ -663,11 +673,10 @@
                "status": "0",
                "hidden": 0
              },
              {
                "id": "e368cae2-96b6-46e5-b537-946a8dc5ede6",
                "created_at": "18/12/2024 11:35:02",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "部门配置",
                "url": "-",
                "path": "",
@@ -682,11 +691,10 @@
                "status": "1",
                "hidden": 0
              },
              {
                "id": "yhbj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "编辑用户",
                "url": "/base/syuser!update",
                "path": null,
@@ -699,13 +707,12 @@
                "resource_type_id": "1",
                "resource_id": "yhgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "yhlb",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "用户列表",
                "url": "/base/syuser!grid",
                "path": null,
@@ -718,13 +725,12 @@
                "resource_type_id": "1",
                "resource_id": "yhgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "yhsc",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "删除用户",
                "url": "/base/syuser!delete",
                "path": "",
@@ -737,13 +743,12 @@
                "resource_type_id": "1",
                "resource_id": "yhgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "yhtj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "添加用户",
                "url": "/base/syuser!save",
                "path": null,
@@ -756,14 +761,14 @@
                "resource_type_id": "1",
                "resource_id": "yhgl",
                "status": "1",
                "hidden": null
                "hidden": 0
              }
            ]
          },
          {
            "id": "zygl",
            "created_at": "25/8/2015 10:34:53",
            "updated_at": "18/12/2024 20:05:23",
            "created_at": "26/12/2024 18:45:57",
            "updated_at": "26/12/2024 18:45:57",
            "name": "资源管理",
            "url": "PermissionResource",
            "path": "/permission/resource",
@@ -776,12 +781,12 @@
            "resource_type_id": "0",
            "resource_id": "xtgl",
            "status": "1",
            "hidden": null,
            "hidden": 0,
            "children": [
              {
                "id": "zybj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "5/9/2024 03:14:57",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "编辑资源",
                "url": "/base/syresource!update",
                "path": null,
@@ -794,13 +799,12 @@
                "resource_type_id": "1",
                "resource_id": "zygl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "zylb",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "资源列表",
                "url": "/base/syresource!treeGrid",
                "path": "",
@@ -813,13 +817,12 @@
                "resource_type_id": "1",
                "resource_id": "zygl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "zysc",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "18/12/2024 11:35:02",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "删除资源",
                "url": "/base/syresource!delete",
                "path": "",
@@ -832,13 +835,12 @@
                "resource_type_id": "1",
                "resource_id": "zygl",
                "status": "1",
                "hidden": null
                "hidden": 0
              },
              {
                "id": "zytj",
                "created_at": "25/8/2015 10:34:53",
                "updated_at": "25/8/2015 10:34:53",
                "created_at": "26/12/2024 18:45:57",
                "updated_at": "26/12/2024 18:45:57",
                "name": "添加资源",
                "url": "/base/syresource!save",
                "path": null,
@@ -851,7 +853,7 @@
                "resource_type_id": "1",
                "resource_id": "zygl",
                "status": "1",
                "hidden": null
                "hidden": 0
              }
            ]
          }
@@ -859,4 +861,4 @@
      }
    ]
  }
]
]
app/init_config/init_run_data.py
@@ -1,17 +1,22 @@
from app.models.base_model import SessionLocal
from app.service.v2.initialize_data import dialog_menu_sync, default_group_sync, default_role_sync, app_register_sync, \
    basic_agent_sync, admin_account_sync
from app.task.fetch_agent import sync_resources_from_json
    basic_agent_sync, admin_account_sync, admin_user_sync
async def sync_default_data():
    db = SessionLocal()
    await dialog_menu_sync(db)  # 小数
    await default_group_sync(db) # 默认组
    await default_role_sync(db) # 默认角色
    await app_register_sync(db) # 注册的应用
    await basic_agent_sync(db) # 开发的agent
    await admin_account_sync(db) # 超管账号
    try:
        await dialog_menu_sync(db)  # 小数
        await default_group_sync(db)  # 默认组
        await default_role_sync(db)  # 默认角色
        await app_register_sync(db)  # 注册的应用
        await basic_agent_sync(db)  # 开发的agent
        await admin_account_sync(db)  #
        await admin_user_sync(db)  #
    except Exception as e:
        print(e)
    finally:
        db.close()
    # await default_role_sync(db)  # 页面资源配置信息
    # await default_role_sync(db)  # 默认的角色资源
app/models/session_model.py
@@ -33,6 +33,7 @@
            'name': self.name,
            'agent_type': self.agent_type,
            'agent_id': self.agent_id,
            'workflow': self.workflow if self.workflow else 0,
            'create_date': self.create_date.strftime("%Y-%m-%d %H:%M:%S"),
            'update_date': self.update_date.strftime("%Y-%m-%d %H:%M:%S"),
        }
app/service/difyService.py
@@ -72,9 +72,9 @@
            # print(response.text)
            return self._handle_response(response)
    async def login(self, username: str, password: str, remember_me=True, invite_token:str="") -> str:
    async def login(self, username: str, password: str, remember_me=True, invite_token:str="", email="") -> str:
        # password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
        data = {"email": f"{username}@basic.com", "password": password, "remember_me": remember_me, "invite_token": invite_token,
        data = {"email":email if email else f"{username}@basic.com", "password": password, "remember_me": remember_me, "invite_token": invite_token,
         "language": "zh-Hans"}
        async with httpx.AsyncClient() as client:
app/service/ragflow.py
@@ -48,13 +48,13 @@
                raise Exception(f"Ragflow registration failed: {response.text}")
            return self._handle_response(response)
    async def login(self, username: str, password: str) -> str:
    async def login(self, username: str, password: str, email="") -> str:
        password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
        async with httpx.AsyncClient() as client:
            response = await client.post(
                f"{self.base_url}/v1/user/login",
                headers={'Content-Type': 'application/json'},
                json={"email": f"{username}@example.com", "password": password}
                json={"email": email if email else f"{username}@example.com", "password": password}
            )
            if response.status_code != 200:
                raise Exception(f"Ragflow login failed: {response.text}")
app/service/session.py
@@ -12,8 +12,10 @@
    def __init__(self, db: Session):
        self.db = db
    def create_session(self, session_id: str, name: str, agent_id: str, agent_type: AgentType, user_id: int,
                       message: dict = None, workflow_type: int = 0) -> Type[SessionModel] | SessionModel:
    def create_session(self, session_id: str, name: str, agent_id: str, agent_type: AgentType, user_id: int, message: dict = None, workflow_type: int = 0) -> Type[
                                                                                                                    SessionModel] | SessionModel:
        """
        创建一个新的会话记录。
@@ -30,6 +32,7 @@
            message = {"role": "user", "content": name}
        existing_session = self.get_session_by_id(session_id)
        if existing_session:
            # existing_session.add_message({"role": "user", "content": name})
            existing_session.add_message(message)
            existing_session.update_date = current_time()
            self.db.commit()
@@ -43,7 +46,7 @@
            agent_type=agent_type,
            tenant_id=user_id,
            workflow=workflow_type,
            message=json.dumps([message])
            message = json.dumps([message])
        )
        self.db.add(new_session)
        self.db.commit()
app/service/v2/initialize_data.py
@@ -3,9 +3,12 @@
import os
import yaml
from passlib.context import CryptContext
from Log import logger
from app.config.const import DIFY, ENV_CONF_PATH
# from app.api import pwd_context
from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW
from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \
    cipher_suite, UserTokenModel
from app.service.auth import UserAppDao
@@ -16,6 +19,8 @@
from app.service.v2.app_register import AppRegisterDao
from app.config.config import settings
from app.utils.password_handle import generate_password
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
async def dialog_menu_sync(db):
@@ -252,4 +257,36 @@
        db.commit()
    except Exception as e:
        print(e)
        db.rollback()
async def admin_user_sync(db):
    try:
        config = {}
        with open(os.path.join(ENV_CONF_PATH, "admin.yaml"), 'r', encoding='utf-8') as file:
            # 加载JSON数据
            config = yaml.safe_load(file)
        # print(config)
        db_user = db.query(UserModel).filter(UserModel.username == config["smart_server"]["account"]).first()
        if db_user:
            print("admin_user_sync: 用户已经存在!")
            return
        register_dict = {}
        for app in [RAGFLOW, DIFY]:
            register_dict[app] = {"id": config[app].get("id", "123"), "name": config[app]["account"],
                                        "pwd":config[app]["password"],
                                        "email": config[app]["account"]}
        # 存储用户信息
        hashed_password = pwd_context.hash(config["smart_server"]["password"])
        user_model = UserModel(username=config["smart_server"]["account"], hashed_password=hashed_password, email="",
                               phone="", login_name="", sync_flag="", creator=0, permission="admin")
        db.add(user_model)
        db.commit()
        db.refresh(user_model)
        u_id = user_model.id
        user_app_dao = UserAppDao(db)
        for k, v in register_dict.items():
            await user_app_dao.update_and_insert_data(v.get("name"), user_model.encrypted_password(v.get("pwd")), v.get("email"), u_id, str(v.get("id")), k)
    except Exception as e:
        print(e)
        db.rollback()