fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# InsightFlow 代码审查报告
|
# InsightFlow 代码审查报告
|
||||||
|
|
||||||
扫描时间: Sat Feb 28 03:03:08 AM CST 2026
|
扫描时间: Sat Feb 28 03:03:50 AM CST 2026
|
||||||
扫描文件数: 40
|
扫描文件数: 40
|
||||||
|
|
||||||
## 扫描的文件列表
|
## 扫描的文件列表
|
||||||
@@ -50,9 +50,9 @@
|
|||||||
|
|
||||||
- 🔴 Critical: 8
|
- 🔴 Critical: 8
|
||||||
- 🟠 Error: 0
|
- 🟠 Error: 0
|
||||||
- 🟡 Warning: 31
|
- 🟡 Warning: 29
|
||||||
- 🔵 Info: 3349
|
- 🔵 Info: 2267
|
||||||
- **总计: 3388**
|
- **总计: 2304**
|
||||||
|
|
||||||
## ✅ 已自动修复的问题
|
## ✅ 已自动修复的问题
|
||||||
|
|
||||||
@@ -60,92 +60,88 @@
|
|||||||
|
|
||||||
## ⚠️ 需要人工确认的问题
|
## ⚠️ 需要人工确认的问题
|
||||||
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:245` [warning] CORS 配置允许所有来源 (*),生产环境应限制具体域名
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:244` [warning] CORS 配置允许所有来源 (*),生产环境应限制具体域名
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:211` [warning] CORS 配置允许所有来源 (*),生产环境应限制具体域名
|
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:210` [warning] CORS 配置允许所有来源 (*),生产环境应限制具体域名
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:608` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:580` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/main.py:339` [warning] CORS 配置允许所有来源 (*),生产环境应限制具体域名
|
- `/root/.openclaw/workspace/projects/insightflow/backend/main.py:339` [warning] CORS 配置允许所有来源 (*),生产环境应限制具体域名
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/developer_ecosystem_manager.py:496` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
- `/root/.openclaw/workspace/projects/insightflow/backend/developer_ecosystem_manager.py:477` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/security_manager.py:58` [critical] 硬编码密钥,应使用环境变量
|
- `/root/.openclaw/workspace/projects/insightflow/backend/security_manager.py:56` [critical] 硬编码密钥,应使用环境变量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:1435` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:1420` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/plugin_manager.py:238` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
- `/root/.openclaw/workspace/projects/insightflow/backend/plugin_manager.py:229` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/test_multimodal.py:136` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
- `/root/.openclaw/workspace/projects/insightflow/backend/test_multimodal.py:136` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/test_phase8_task6.py:531` [critical] 硬编码 API Key,应使用环境变量
|
- `/root/.openclaw/workspace/projects/insightflow/backend/test_phase8_task6.py:530` [critical] 硬编码 API Key,应使用环境变量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/search_manager.py:2097` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
- `/root/.openclaw/workspace/projects/insightflow/backend/search_manager.py:2079` [critical] 潜在的 SQL 注入风险,使用参数化查询
|
||||||
|
|
||||||
## 📋 其他发现的问题
|
## 📋 其他发现的问题
|
||||||
|
|
||||||
### duplicate_import
|
### duplicate_import
|
||||||
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/tingwu_client.py:73` - 重复导入: from alibabacloud_tea_openapi import models as open_api_models
|
- `/root/.openclaw/workspace/projects/insightflow/backend/tingwu_client.py:72` - 重复导入: from alibabacloud_tea_openapi import models as open_api_models
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/tingwu_client.py:74` - 重复导入: from alibabacloud_tingwu20230930 import models as tingwu_models
|
- `/root/.openclaw/workspace/projects/insightflow/backend/tingwu_client.py:73` - 重复导入: from alibabacloud_tingwu20230930 import models as tingwu_models
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/tingwu_client.py:75` - 重复导入: from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient
|
- `/root/.openclaw/workspace/projects/insightflow/backend/tingwu_client.py:74` - 重复导入: from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/main.py:1177` - 重复导入: import re
|
- `/root/.openclaw/workspace/projects/insightflow/backend/main.py:1113` - 重复导入: import re
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/knowledge_reasoner.py:122` - 重复导入: import re
|
- `/root/.openclaw/workspace/projects/insightflow/backend/knowledge_reasoner.py:118` - 重复导入: import re
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ai_manager.py:446` - 重复导入: import re
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ai_manager.py:433` - 重复导入: import re
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/llm_client.py:126` - 重复导入: import re
|
- `/root/.openclaw/workspace/projects/insightflow/backend/llm_client.py:122` - 重复导入: import re
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/export_manager.py:282` - 重复导入: import csv
|
- `/root/.openclaw/workspace/projects/insightflow/backend/export_manager.py:278` - 重复导入: import csv
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/test_phase8_task8.py:325` - 重复导入: import random
|
- `/root/.openclaw/workspace/projects/insightflow/backend/test_phase8_task8.py:324` - 重复导入: import random
|
||||||
|
|
||||||
### extra_blank_line
|
### extra_blank_line
|
||||||
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:14` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:13` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:28` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:27` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:408` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:430` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:445` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:467` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:488` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:510` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:11` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:10` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:24` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:23` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:315` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:314` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:340` - 多余的空行
|
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:339` - 多余的空行
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/test_phase8_task5.py:35` - 多余的空行
|
|
||||||
- ... 还有 1081 个类似问题
|
|
||||||
|
|
||||||
### line_too_long
|
### line_too_long
|
||||||
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:960` - 行长度 147 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:932` - 行长度 147 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/db_manager.py:168` - 行长度 125 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/db_manager.py:161` - 行长度 125 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/db_manager.py:704` - 行长度 129 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/db_manager.py:697` - 行长度 129 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/main.py:4571` - 行长度 130 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/main.py:4385` - 行长度 130 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/developer_ecosystem_manager.py:963` - 行长度 122 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/developer_ecosystem_manager.py:944` - 行长度 122 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/llm_client.py:109` - 行长度 131 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/llm_client.py:105` - 行长度 131 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:783` - 行长度 121 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:768` - 行长度 121 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:785` - 行长度 122 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:770` - 行长度 122 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:897` - 行长度 121 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:882` - 行长度 121 超过 120 字符
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:975` - 行长度 121 超过 120 字符
|
- `/root/.openclaw/workspace/projects/insightflow/backend/localization_manager.py:960` - 行长度 121 超过 120 字符
|
||||||
- ... 还有 4 个类似问题
|
- ... 还有 4 个类似问题
|
||||||
|
|
||||||
### magic_number
|
### magic_number
|
||||||
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:50` - 魔法数字 8,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:49` - 魔法数字 8,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:94` - 魔法数字 2,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:93` - 魔法数字 2,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:114` - 魔法数字 120,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:113` - 魔法数字 120,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:116` - 魔法数字 120,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:115` - 魔法数字 120,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:126` - 魔法数字 2,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:125` - 魔法数字 2,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:299` - 魔法数字 8,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:303` - 魔法数字 8,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:315` - 魔法数字 8,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:337` - 魔法数字 8,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:400` - 魔法数字 10,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:422` - 魔法数字 10,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:402` - 魔法数字 10,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:424` - 魔法数字 10,建议提取为常量
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:403` - 魔法数字 10,建议提取为常量
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:425` - 魔法数字 10,建议提取为常量
|
||||||
- ... 还有 2178 个类似问题
|
- ... 还有 2178 个类似问题
|
||||||
|
|
||||||
### missing_type_annotation
|
### missing_type_annotation
|
||||||
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2736` - 函数 '_row_to_alert_rule' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2708` - 函数 '_row_to_alert_rule' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2758` - 函数 '_row_to_alert_channel' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2730` - 函数 '_row_to_alert_channel' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2774` - 函数 '_row_to_alert' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2746` - 函数 '_row_to_alert' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2796` - 函数 '_row_to_suppression_rule' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2768` - 函数 '_row_to_suppression_rule' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2808` - 函数 '_row_to_resource_metric' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2780` - 函数 '_row_to_resource_metric' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2821` - 函数 '_row_to_capacity_plan' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2793` - 函数 '_row_to_capacity_plan' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2835` - 函数 '_row_to_auto_scaling_policy' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2807` - 函数 '_row_to_auto_scaling_policy' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2854` - 函数 '_row_to_scaling_event' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2826` - 函数 '_row_to_scaling_event' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2870` - 函数 '_row_to_health_check' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2842` - 函数 '_row_to_health_check' 的参数 'row' 缺少类型注解
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2889` - 函数 '_row_to_health_check_result' 的参数 'row' 缺少类型注解
|
- `/root/.openclaw/workspace/projects/insightflow/backend/ops_manager.py:2861` - 函数 '_row_to_health_check_result' 的参数 'row' 缺少类型注解
|
||||||
- ... 还有 60 个类似问题
|
- ... 还有 60 个类似问题
|
||||||
|
|
||||||
### unused_import
|
### unused_import
|
||||||
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:10` - 未使用的导入: sys
|
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:11` - 未使用的导入: Any
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/auto_code_fixer.py:12` - 未使用的导入: Any
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/code_reviewer.py:9` - 未使用的导入: Any
|
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/workflow_manager.py:16` - 未使用的导入: urllib.request
|
- `/root/.openclaw/workspace/projects/insightflow/backend/workflow_manager.py:16` - 未使用的导入: urllib.request
|
||||||
- `/root/.openclaw/workspace/projects/insightflow/backend/plugin_manager.py:14` - 未使用的导入: urllib.request
|
- `/root/.openclaw/workspace/projects/insightflow/backend/plugin_manager.py:14` - 未使用的导入: urllib.request
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import ast
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -284,6 +283,7 @@ class CodeFixer:
|
|||||||
"extra_blank_line",
|
"extra_blank_line",
|
||||||
"old_string_format",
|
"old_string_format",
|
||||||
"format_method",
|
"format_method",
|
||||||
|
"unused_import",
|
||||||
}
|
}
|
||||||
|
|
||||||
# 按文件分组
|
# 按文件分组
|
||||||
@@ -295,6 +295,10 @@ class CodeFixer:
|
|||||||
files_to_fix[issue.file_path].append(issue)
|
files_to_fix[issue.file_path].append(issue)
|
||||||
|
|
||||||
for file_path, file_issues in files_to_fix.items():
|
for file_path, file_issues in files_to_fix.items():
|
||||||
|
# 跳过自动生成的文件
|
||||||
|
if "auto_code_fixer.py" in file_path or "code_reviewer.py" in file_path:
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(file_path, "r", encoding="utf-8") as f:
|
with open(file_path, "r", encoding="utf-8") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
@@ -302,14 +306,32 @@ class CodeFixer:
|
|||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
fixed_lines = set()
|
||||||
|
|
||||||
# 修复行尾空格
|
# 修复行尾空格
|
||||||
for issue in file_issues:
|
for issue in file_issues:
|
||||||
if issue.issue_type == "trailing_whitespace":
|
if issue.issue_type == "trailing_whitespace":
|
||||||
line_idx = issue.line_no - 1
|
line_idx = issue.line_no - 1
|
||||||
if 0 <= line_idx < len(lines):
|
if 0 <= line_idx < len(lines) and line_idx not in fixed_lines:
|
||||||
lines[line_idx] = lines[line_idx].rstrip()
|
lines[line_idx] = lines[line_idx].rstrip()
|
||||||
|
fixed_lines.add(line_idx)
|
||||||
self.fixed_issues.append(issue)
|
self.fixed_issues.append(issue)
|
||||||
|
|
||||||
|
# 修复多余的空行
|
||||||
|
for issue in file_issues:
|
||||||
|
if issue.issue_type == "extra_blank_line":
|
||||||
|
line_idx = issue.line_no - 1
|
||||||
|
if 0 <= line_idx < len(lines) and line_idx not in fixed_lines:
|
||||||
|
# 检查是否是多余的空行
|
||||||
|
if line_idx > 0 and lines[line_idx].strip() == "" and lines[line_idx - 1].strip() == "":
|
||||||
|
lines.pop(line_idx)
|
||||||
|
fixed_lines.add(line_idx)
|
||||||
|
self.fixed_issues.append(issue)
|
||||||
|
# 调整后续行号
|
||||||
|
for other_issue in file_issues:
|
||||||
|
if other_issue.line_no > issue.line_no:
|
||||||
|
other_issue.line_no -= 1
|
||||||
|
|
||||||
# 写回文件
|
# 写回文件
|
||||||
try:
|
try:
|
||||||
with open(file_path, "w", encoding="utf-8") as f:
|
with open(file_path, "w", encoding="utf-8") as f:
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import httpx
|
|||||||
# Database path
|
# Database path
|
||||||
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
||||||
|
|
||||||
|
|
||||||
class ModelType(StrEnum):
|
class ModelType(StrEnum):
|
||||||
"""模型类型"""
|
"""模型类型"""
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ class ModelType(StrEnum):
|
|||||||
SUMMARIZATION = "summarization" # 摘要
|
SUMMARIZATION = "summarization" # 摘要
|
||||||
PREDICTION = "prediction" # 预测
|
PREDICTION = "prediction" # 预测
|
||||||
|
|
||||||
|
|
||||||
class ModelStatus(StrEnum):
|
class ModelStatus(StrEnum):
|
||||||
"""模型状态"""
|
"""模型状态"""
|
||||||
|
|
||||||
@@ -46,7 +44,6 @@ class ModelStatus(StrEnum):
|
|||||||
FAILED = "failed"
|
FAILED = "failed"
|
||||||
ARCHIVED = "archived"
|
ARCHIVED = "archived"
|
||||||
|
|
||||||
|
|
||||||
class MultimodalProvider(StrEnum):
|
class MultimodalProvider(StrEnum):
|
||||||
"""多模态模型提供商"""
|
"""多模态模型提供商"""
|
||||||
|
|
||||||
@@ -55,7 +52,6 @@ class MultimodalProvider(StrEnum):
|
|||||||
GEMINI = "gemini-pro-vision"
|
GEMINI = "gemini-pro-vision"
|
||||||
KIMI_VL = "kimi-vl"
|
KIMI_VL = "kimi-vl"
|
||||||
|
|
||||||
|
|
||||||
class PredictionType(StrEnum):
|
class PredictionType(StrEnum):
|
||||||
"""预测类型"""
|
"""预测类型"""
|
||||||
|
|
||||||
@@ -64,7 +60,6 @@ class PredictionType(StrEnum):
|
|||||||
ENTITY_GROWTH = "entity_growth" # 实体增长预测
|
ENTITY_GROWTH = "entity_growth" # 实体增长预测
|
||||||
RELATION_EVOLUTION = "relation_evolution" # 关系演变预测
|
RELATION_EVOLUTION = "relation_evolution" # 关系演变预测
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CustomModel:
|
class CustomModel:
|
||||||
"""自定义模型"""
|
"""自定义模型"""
|
||||||
@@ -84,7 +79,6 @@ class CustomModel:
|
|||||||
trained_at: str | None
|
trained_at: str | None
|
||||||
created_by: str
|
created_by: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TrainingSample:
|
class TrainingSample:
|
||||||
"""训练样本"""
|
"""训练样本"""
|
||||||
@@ -96,7 +90,6 @@ class TrainingSample:
|
|||||||
metadata: dict
|
metadata: dict
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MultimodalAnalysis:
|
class MultimodalAnalysis:
|
||||||
"""多模态分析结果"""
|
"""多模态分析结果"""
|
||||||
@@ -113,7 +106,6 @@ class MultimodalAnalysis:
|
|||||||
cost: float
|
cost: float
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class KnowledgeGraphRAG:
|
class KnowledgeGraphRAG:
|
||||||
"""基于知识图谱的 RAG 配置"""
|
"""基于知识图谱的 RAG 配置"""
|
||||||
@@ -130,7 +122,6 @@ class KnowledgeGraphRAG:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RAGQuery:
|
class RAGQuery:
|
||||||
"""RAG 查询记录"""
|
"""RAG 查询记录"""
|
||||||
@@ -146,7 +137,6 @@ class RAGQuery:
|
|||||||
latency_ms: int
|
latency_ms: int
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PredictionModel:
|
class PredictionModel:
|
||||||
"""预测模型"""
|
"""预测模型"""
|
||||||
@@ -166,7 +156,6 @@ class PredictionModel:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PredictionResult:
|
class PredictionResult:
|
||||||
"""预测结果"""
|
"""预测结果"""
|
||||||
@@ -182,7 +171,6 @@ class PredictionResult:
|
|||||||
is_correct: bool | None
|
is_correct: bool | None
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SmartSummary:
|
class SmartSummary:
|
||||||
"""智能摘要"""
|
"""智能摘要"""
|
||||||
@@ -200,7 +188,6 @@ class SmartSummary:
|
|||||||
tokens_used: int
|
tokens_used: int
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
class AIManager:
|
class AIManager:
|
||||||
"""AI 能力管理主类"""
|
"""AI 能力管理主类"""
|
||||||
|
|
||||||
@@ -1422,11 +1409,9 @@ class AIManager:
|
|||||||
created_at=row["created_at"],
|
created_at=row["created_at"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_ai_manager = None
|
_ai_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_ai_manager() -> AIManager:
|
def get_ai_manager() -> AIManager:
|
||||||
global _ai_manager
|
global _ai_manager
|
||||||
if _ai_manager is None:
|
if _ai_manager is None:
|
||||||
|
|||||||
@@ -15,13 +15,11 @@ from enum import Enum
|
|||||||
|
|
||||||
DB_PATH = os.getenv("DB_PATH", "/app/data/insightflow.db")
|
DB_PATH = os.getenv("DB_PATH", "/app/data/insightflow.db")
|
||||||
|
|
||||||
|
|
||||||
class ApiKeyStatus(Enum):
|
class ApiKeyStatus(Enum):
|
||||||
ACTIVE = "active"
|
ACTIVE = "active"
|
||||||
REVOKED = "revoked"
|
REVOKED = "revoked"
|
||||||
EXPIRED = "expired"
|
EXPIRED = "expired"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ApiKey:
|
class ApiKey:
|
||||||
id: str
|
id: str
|
||||||
@@ -39,7 +37,6 @@ class ApiKey:
|
|||||||
revoked_reason: str | None
|
revoked_reason: str | None
|
||||||
total_calls: int = 0
|
total_calls: int = 0
|
||||||
|
|
||||||
|
|
||||||
class ApiKeyManager:
|
class ApiKeyManager:
|
||||||
"""API Key 管理器"""
|
"""API Key 管理器"""
|
||||||
|
|
||||||
@@ -497,11 +494,9 @@ class ApiKeyManager:
|
|||||||
total_calls=row["total_calls"],
|
total_calls=row["total_calls"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 全局实例
|
# 全局实例
|
||||||
_api_key_manager: ApiKeyManager | None = None
|
_api_key_manager: ApiKeyManager | None = None
|
||||||
|
|
||||||
|
|
||||||
def get_api_key_manager() -> ApiKeyManager:
|
def get_api_key_manager() -> ApiKeyManager:
|
||||||
"""获取 API Key 管理器实例"""
|
"""获取 API Key 管理器实例"""
|
||||||
global _api_key_manager
|
global _api_key_manager
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from datetime import datetime, timedelta
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class SharePermission(Enum):
|
class SharePermission(Enum):
|
||||||
"""分享权限级别"""
|
"""分享权限级别"""
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ class SharePermission(Enum):
|
|||||||
EDIT = "edit" # 可编辑
|
EDIT = "edit" # 可编辑
|
||||||
ADMIN = "admin" # 管理员
|
ADMIN = "admin" # 管理员
|
||||||
|
|
||||||
|
|
||||||
class CommentTargetType(Enum):
|
class CommentTargetType(Enum):
|
||||||
"""评论目标类型"""
|
"""评论目标类型"""
|
||||||
|
|
||||||
@@ -29,7 +27,6 @@ class CommentTargetType(Enum):
|
|||||||
TRANSCRIPT = "transcript" # 转录文本评论
|
TRANSCRIPT = "transcript" # 转录文本评论
|
||||||
PROJECT = "project" # 项目级评论
|
PROJECT = "project" # 项目级评论
|
||||||
|
|
||||||
|
|
||||||
class ChangeType(Enum):
|
class ChangeType(Enum):
|
||||||
"""变更类型"""
|
"""变更类型"""
|
||||||
|
|
||||||
@@ -39,7 +36,6 @@ class ChangeType(Enum):
|
|||||||
MERGE = "merge" # 合并
|
MERGE = "merge" # 合并
|
||||||
SPLIT = "split" # 拆分
|
SPLIT = "split" # 拆分
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ProjectShare:
|
class ProjectShare:
|
||||||
"""项目分享链接"""
|
"""项目分享链接"""
|
||||||
@@ -58,7 +54,6 @@ class ProjectShare:
|
|||||||
allow_download: bool # 允许下载
|
allow_download: bool # 允许下载
|
||||||
allow_export: bool # 允许导出
|
allow_export: bool # 允许导出
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Comment:
|
class Comment:
|
||||||
"""评论/批注"""
|
"""评论/批注"""
|
||||||
@@ -79,7 +74,6 @@ class Comment:
|
|||||||
mentions: list[str] # 提及的用户
|
mentions: list[str] # 提及的用户
|
||||||
attachments: list[dict] # 附件
|
attachments: list[dict] # 附件
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ChangeRecord:
|
class ChangeRecord:
|
||||||
"""变更记录"""
|
"""变更记录"""
|
||||||
@@ -101,7 +95,6 @@ class ChangeRecord:
|
|||||||
reverted_at: str | None # 回滚时间
|
reverted_at: str | None # 回滚时间
|
||||||
reverted_by: str | None # 回滚者
|
reverted_by: str | None # 回滚者
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TeamMember:
|
class TeamMember:
|
||||||
"""团队成员"""
|
"""团队成员"""
|
||||||
@@ -117,7 +110,6 @@ class TeamMember:
|
|||||||
last_active_at: str | None # 最后活跃时间
|
last_active_at: str | None # 最后活跃时间
|
||||||
permissions: list[str] # 具体权限列表
|
permissions: list[str] # 具体权限列表
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TeamSpace:
|
class TeamSpace:
|
||||||
"""团队空间"""
|
"""团队空间"""
|
||||||
@@ -132,7 +124,6 @@ class TeamSpace:
|
|||||||
project_count: int
|
project_count: int
|
||||||
settings: dict[str, Any] # 团队设置
|
settings: dict[str, Any] # 团队设置
|
||||||
|
|
||||||
|
|
||||||
class CollaborationManager:
|
class CollaborationManager:
|
||||||
"""协作管理主类"""
|
"""协作管理主类"""
|
||||||
|
|
||||||
@@ -987,11 +978,9 @@ class CollaborationManager:
|
|||||||
)
|
)
|
||||||
self.db.conn.commit()
|
self.db.conn.commit()
|
||||||
|
|
||||||
|
|
||||||
# 全局协作管理器实例
|
# 全局协作管理器实例
|
||||||
_collaboration_manager = None
|
_collaboration_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_collaboration_manager(db_manager=None) -> None:
|
def get_collaboration_manager(db_manager=None) -> None:
|
||||||
"""获取协作管理器单例"""
|
"""获取协作管理器单例"""
|
||||||
global _collaboration_manager
|
global _collaboration_manager
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from datetime import datetime
|
|||||||
|
|
||||||
DB_PATH = os.getenv("DB_PATH", "/app/data/insightflow.db")
|
DB_PATH = os.getenv("DB_PATH", "/app/data/insightflow.db")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Project:
|
class Project:
|
||||||
id: str
|
id: str
|
||||||
@@ -23,7 +22,6 @@ class Project:
|
|||||||
created_at: str = ""
|
created_at: str = ""
|
||||||
updated_at: str = ""
|
updated_at: str = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Entity:
|
class Entity:
|
||||||
id: str
|
id: str
|
||||||
@@ -44,7 +42,6 @@ class Entity:
|
|||||||
if self.attributes is None:
|
if self.attributes is None:
|
||||||
self.attributes = {}
|
self.attributes = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AttributeTemplate:
|
class AttributeTemplate:
|
||||||
"""属性模板定义"""
|
"""属性模板定义"""
|
||||||
@@ -65,7 +62,6 @@ class AttributeTemplate:
|
|||||||
if self.options is None:
|
if self.options is None:
|
||||||
self.options = []
|
self.options = []
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EntityAttribute:
|
class EntityAttribute:
|
||||||
"""实体属性值"""
|
"""实体属性值"""
|
||||||
@@ -86,7 +82,6 @@ class EntityAttribute:
|
|||||||
if self.options is None:
|
if self.options is None:
|
||||||
self.options = []
|
self.options = []
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AttributeHistory:
|
class AttributeHistory:
|
||||||
"""属性变更历史"""
|
"""属性变更历史"""
|
||||||
@@ -100,7 +95,6 @@ class AttributeHistory:
|
|||||||
changed_at: str = ""
|
changed_at: str = ""
|
||||||
change_reason: str = ""
|
change_reason: str = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EntityMention:
|
class EntityMention:
|
||||||
id: str
|
id: str
|
||||||
@@ -111,7 +105,6 @@ class EntityMention:
|
|||||||
text_snippet: str
|
text_snippet: str
|
||||||
confidence: float = 1.0
|
confidence: float = 1.0
|
||||||
|
|
||||||
|
|
||||||
class DatabaseManager:
|
class DatabaseManager:
|
||||||
def __init__(self, db_path: str = DB_PATH):
|
def __init__(self, db_path: str = DB_PATH):
|
||||||
self.db_path = db_path
|
self.db_path = db_path
|
||||||
@@ -1298,11 +1291,9 @@ class DatabaseManager:
|
|||||||
conn.close()
|
conn.close()
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_db_manager = None
|
_db_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_db_manager() -> DatabaseManager:
|
def get_db_manager() -> DatabaseManager:
|
||||||
global _db_manager
|
global _db_manager
|
||||||
if _db_manager is None:
|
if _db_manager is None:
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ from enum import StrEnum
|
|||||||
# Database path
|
# Database path
|
||||||
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
||||||
|
|
||||||
|
|
||||||
class SDKLanguage(StrEnum):
|
class SDKLanguage(StrEnum):
|
||||||
"""SDK 语言类型"""
|
"""SDK 语言类型"""
|
||||||
|
|
||||||
@@ -32,7 +31,6 @@ class SDKLanguage(StrEnum):
|
|||||||
JAVA = "java"
|
JAVA = "java"
|
||||||
RUST = "rust"
|
RUST = "rust"
|
||||||
|
|
||||||
|
|
||||||
class SDKStatus(StrEnum):
|
class SDKStatus(StrEnum):
|
||||||
"""SDK 状态"""
|
"""SDK 状态"""
|
||||||
|
|
||||||
@@ -42,7 +40,6 @@ class SDKStatus(StrEnum):
|
|||||||
DEPRECATED = "deprecated" # 已弃用
|
DEPRECATED = "deprecated" # 已弃用
|
||||||
ARCHIVED = "archived" # 已归档
|
ARCHIVED = "archived" # 已归档
|
||||||
|
|
||||||
|
|
||||||
class TemplateCategory(StrEnum):
|
class TemplateCategory(StrEnum):
|
||||||
"""模板分类"""
|
"""模板分类"""
|
||||||
|
|
||||||
@@ -53,7 +50,6 @@ class TemplateCategory(StrEnum):
|
|||||||
TECH = "tech" # 科技
|
TECH = "tech" # 科技
|
||||||
GENERAL = "general" # 通用
|
GENERAL = "general" # 通用
|
||||||
|
|
||||||
|
|
||||||
class TemplateStatus(StrEnum):
|
class TemplateStatus(StrEnum):
|
||||||
"""模板状态"""
|
"""模板状态"""
|
||||||
|
|
||||||
@@ -63,7 +59,6 @@ class TemplateStatus(StrEnum):
|
|||||||
PUBLISHED = "published" # 已发布
|
PUBLISHED = "published" # 已发布
|
||||||
UNLISTED = "unlisted" # 未列出
|
UNLISTED = "unlisted" # 未列出
|
||||||
|
|
||||||
|
|
||||||
class PluginStatus(StrEnum):
|
class PluginStatus(StrEnum):
|
||||||
"""插件状态"""
|
"""插件状态"""
|
||||||
|
|
||||||
@@ -74,7 +69,6 @@ class PluginStatus(StrEnum):
|
|||||||
PUBLISHED = "published" # 已发布
|
PUBLISHED = "published" # 已发布
|
||||||
SUSPENDED = "suspended" # 已暂停
|
SUSPENDED = "suspended" # 已暂停
|
||||||
|
|
||||||
|
|
||||||
class PluginCategory(StrEnum):
|
class PluginCategory(StrEnum):
|
||||||
"""插件分类"""
|
"""插件分类"""
|
||||||
|
|
||||||
@@ -85,7 +79,6 @@ class PluginCategory(StrEnum):
|
|||||||
SECURITY = "security" # 安全
|
SECURITY = "security" # 安全
|
||||||
CUSTOM = "custom" # 自定义
|
CUSTOM = "custom" # 自定义
|
||||||
|
|
||||||
|
|
||||||
class DeveloperStatus(StrEnum):
|
class DeveloperStatus(StrEnum):
|
||||||
"""开发者认证状态"""
|
"""开发者认证状态"""
|
||||||
|
|
||||||
@@ -95,7 +88,6 @@ class DeveloperStatus(StrEnum):
|
|||||||
CERTIFIED = "certified" # 已认证(高级)
|
CERTIFIED = "certified" # 已认证(高级)
|
||||||
SUSPENDED = "suspended" # 已暂停
|
SUSPENDED = "suspended" # 已暂停
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SDKRelease:
|
class SDKRelease:
|
||||||
"""SDK 发布"""
|
"""SDK 发布"""
|
||||||
@@ -121,7 +113,6 @@ class SDKRelease:
|
|||||||
published_at: str | None
|
published_at: str | None
|
||||||
created_by: str
|
created_by: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SDKVersion:
|
class SDKVersion:
|
||||||
"""SDK 版本历史"""
|
"""SDK 版本历史"""
|
||||||
@@ -138,7 +129,6 @@ class SDKVersion:
|
|||||||
download_count: int
|
download_count: int
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TemplateMarketItem:
|
class TemplateMarketItem:
|
||||||
"""模板市场项目"""
|
"""模板市场项目"""
|
||||||
@@ -170,7 +160,6 @@ class TemplateMarketItem:
|
|||||||
updated_at: str
|
updated_at: str
|
||||||
published_at: str | None
|
published_at: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TemplateReview:
|
class TemplateReview:
|
||||||
"""模板评价"""
|
"""模板评价"""
|
||||||
@@ -186,7 +175,6 @@ class TemplateReview:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PluginMarketItem:
|
class PluginMarketItem:
|
||||||
"""插件市场项目"""
|
"""插件市场项目"""
|
||||||
@@ -225,7 +213,6 @@ class PluginMarketItem:
|
|||||||
reviewed_at: str | None
|
reviewed_at: str | None
|
||||||
review_notes: str | None
|
review_notes: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PluginReview:
|
class PluginReview:
|
||||||
"""插件评价"""
|
"""插件评价"""
|
||||||
@@ -241,7 +228,6 @@ class PluginReview:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DeveloperProfile:
|
class DeveloperProfile:
|
||||||
"""开发者档案"""
|
"""开发者档案"""
|
||||||
@@ -265,7 +251,6 @@ class DeveloperProfile:
|
|||||||
updated_at: str
|
updated_at: str
|
||||||
verified_at: str | None
|
verified_at: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DeveloperRevenue:
|
class DeveloperRevenue:
|
||||||
"""开发者收益"""
|
"""开发者收益"""
|
||||||
@@ -283,7 +268,6 @@ class DeveloperRevenue:
|
|||||||
transaction_id: str
|
transaction_id: str
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CodeExample:
|
class CodeExample:
|
||||||
"""代码示例"""
|
"""代码示例"""
|
||||||
@@ -306,7 +290,6 @@ class CodeExample:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class APIDocumentation:
|
class APIDocumentation:
|
||||||
"""API 文档生成记录"""
|
"""API 文档生成记录"""
|
||||||
@@ -320,7 +303,6 @@ class APIDocumentation:
|
|||||||
generated_at: str
|
generated_at: str
|
||||||
generated_by: str
|
generated_by: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DeveloperPortalConfig:
|
class DeveloperPortalConfig:
|
||||||
"""开发者门户配置"""
|
"""开发者门户配置"""
|
||||||
@@ -344,7 +326,6 @@ class DeveloperPortalConfig:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
class DeveloperEcosystemManager:
|
class DeveloperEcosystemManager:
|
||||||
"""开发者生态系统管理主类"""
|
"""开发者生态系统管理主类"""
|
||||||
|
|
||||||
@@ -2003,11 +1984,9 @@ class DeveloperEcosystemManager:
|
|||||||
updated_at=row["updated_at"],
|
updated_at=row["updated_at"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_developer_ecosystem_manager = None
|
_developer_ecosystem_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_developer_ecosystem_manager() -> DeveloperEcosystemManager:
|
def get_developer_ecosystem_manager() -> DeveloperEcosystemManager:
|
||||||
"""获取开发者生态系统管理器单例"""
|
"""获取开发者生态系统管理器单例"""
|
||||||
global _developer_ecosystem_manager
|
global _developer_ecosystem_manager
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ Document Processor - Phase 3
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class DocumentProcessor:
|
class DocumentProcessor:
|
||||||
"""文档处理器 - 提取 PDF/DOCX 文本"""
|
"""文档处理器 - 提取 PDF/DOCX 文本"""
|
||||||
|
|
||||||
@@ -150,7 +149,6 @@ class DocumentProcessor:
|
|||||||
ext = os.path.splitext(filename.lower())[1]
|
ext = os.path.splitext(filename.lower())[1]
|
||||||
return ext in self.supported_formats
|
return ext in self.supported_formats
|
||||||
|
|
||||||
|
|
||||||
# 简单的文本提取器(不需要外部依赖)
|
# 简单的文本提取器(不需要外部依赖)
|
||||||
class SimpleTextExtractor:
|
class SimpleTextExtractor:
|
||||||
"""简单的文本提取器,用于测试"""
|
"""简单的文本提取器,用于测试"""
|
||||||
@@ -167,7 +165,6 @@ class SimpleTextExtractor:
|
|||||||
|
|
||||||
return content.decode("latin-1", errors="ignore")
|
return content.decode("latin-1", errors="ignore")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 测试
|
# 测试
|
||||||
processor = DocumentProcessor()
|
processor = DocumentProcessor()
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ from typing import Any
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SSOProvider(StrEnum):
|
class SSOProvider(StrEnum):
|
||||||
"""SSO 提供商类型"""
|
"""SSO 提供商类型"""
|
||||||
|
|
||||||
@@ -33,7 +32,6 @@ class SSOProvider(StrEnum):
|
|||||||
GOOGLE = "google" # Google Workspace
|
GOOGLE = "google" # Google Workspace
|
||||||
CUSTOM_SAML = "custom_saml" # 自定义 SAML
|
CUSTOM_SAML = "custom_saml" # 自定义 SAML
|
||||||
|
|
||||||
|
|
||||||
class SSOStatus(StrEnum):
|
class SSOStatus(StrEnum):
|
||||||
"""SSO 配置状态"""
|
"""SSO 配置状态"""
|
||||||
|
|
||||||
@@ -42,7 +40,6 @@ class SSOStatus(StrEnum):
|
|||||||
ACTIVE = "active" # 已启用
|
ACTIVE = "active" # 已启用
|
||||||
ERROR = "error" # 配置错误
|
ERROR = "error" # 配置错误
|
||||||
|
|
||||||
|
|
||||||
class SCIMSyncStatus(StrEnum):
|
class SCIMSyncStatus(StrEnum):
|
||||||
"""SCIM 同步状态"""
|
"""SCIM 同步状态"""
|
||||||
|
|
||||||
@@ -51,7 +48,6 @@ class SCIMSyncStatus(StrEnum):
|
|||||||
SUCCESS = "success" # 同步成功
|
SUCCESS = "success" # 同步成功
|
||||||
FAILED = "failed" # 同步失败
|
FAILED = "failed" # 同步失败
|
||||||
|
|
||||||
|
|
||||||
class AuditLogExportFormat(StrEnum):
|
class AuditLogExportFormat(StrEnum):
|
||||||
"""审计日志导出格式"""
|
"""审计日志导出格式"""
|
||||||
|
|
||||||
@@ -60,7 +56,6 @@ class AuditLogExportFormat(StrEnum):
|
|||||||
PDF = "pdf"
|
PDF = "pdf"
|
||||||
XLSX = "xlsx"
|
XLSX = "xlsx"
|
||||||
|
|
||||||
|
|
||||||
class DataRetentionAction(StrEnum):
|
class DataRetentionAction(StrEnum):
|
||||||
"""数据保留策略动作"""
|
"""数据保留策略动作"""
|
||||||
|
|
||||||
@@ -68,7 +63,6 @@ class DataRetentionAction(StrEnum):
|
|||||||
DELETE = "delete" # 删除
|
DELETE = "delete" # 删除
|
||||||
ANONYMIZE = "anonymize" # 匿名化
|
ANONYMIZE = "anonymize" # 匿名化
|
||||||
|
|
||||||
|
|
||||||
class ComplianceStandard(StrEnum):
|
class ComplianceStandard(StrEnum):
|
||||||
"""合规标准"""
|
"""合规标准"""
|
||||||
|
|
||||||
@@ -78,7 +72,6 @@ class ComplianceStandard(StrEnum):
|
|||||||
HIPAA = "hipaa"
|
HIPAA = "hipaa"
|
||||||
PCI_DSS = "pci_dss"
|
PCI_DSS = "pci_dss"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SSOConfig:
|
class SSOConfig:
|
||||||
"""SSO 配置数据类"""
|
"""SSO 配置数据类"""
|
||||||
@@ -111,7 +104,6 @@ class SSOConfig:
|
|||||||
last_tested_at: datetime | None
|
last_tested_at: datetime | None
|
||||||
last_error: str | None
|
last_error: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SCIMConfig:
|
class SCIMConfig:
|
||||||
"""SCIM 配置数据类"""
|
"""SCIM 配置数据类"""
|
||||||
@@ -136,7 +128,6 @@ class SCIMConfig:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SCIMUser:
|
class SCIMUser:
|
||||||
"""SCIM 用户数据类"""
|
"""SCIM 用户数据类"""
|
||||||
@@ -156,7 +147,6 @@ class SCIMUser:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AuditLogExport:
|
class AuditLogExport:
|
||||||
"""审计日志导出记录"""
|
"""审计日志导出记录"""
|
||||||
@@ -181,7 +171,6 @@ class AuditLogExport:
|
|||||||
completed_at: datetime | None
|
completed_at: datetime | None
|
||||||
error_message: str | None
|
error_message: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DataRetentionPolicy:
|
class DataRetentionPolicy:
|
||||||
"""数据保留策略"""
|
"""数据保留策略"""
|
||||||
@@ -209,7 +198,6 @@ class DataRetentionPolicy:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DataRetentionJob:
|
class DataRetentionJob:
|
||||||
"""数据保留任务"""
|
"""数据保留任务"""
|
||||||
@@ -227,7 +215,6 @@ class DataRetentionJob:
|
|||||||
details: dict[str, Any]
|
details: dict[str, Any]
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SAMLAuthRequest:
|
class SAMLAuthRequest:
|
||||||
"""SAML 认证请求"""
|
"""SAML 认证请求"""
|
||||||
@@ -242,7 +229,6 @@ class SAMLAuthRequest:
|
|||||||
used: bool
|
used: bool
|
||||||
used_at: datetime | None
|
used_at: datetime | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SAMLAuthResponse:
|
class SAMLAuthResponse:
|
||||||
"""SAML 认证响应"""
|
"""SAML 认证响应"""
|
||||||
@@ -259,7 +245,6 @@ class SAMLAuthResponse:
|
|||||||
processed_at: datetime | None
|
processed_at: datetime | None
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
class EnterpriseManager:
|
class EnterpriseManager:
|
||||||
"""企业级功能管理器"""
|
"""企业级功能管理器"""
|
||||||
|
|
||||||
@@ -2109,11 +2094,9 @@ class EnterpriseManager:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 全局实例
|
# 全局实例
|
||||||
_enterprise_manager = None
|
_enterprise_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_enterprise_manager(db_path: str = "insightflow.db") -> EnterpriseManager:
|
def get_enterprise_manager(db_path: str = "insightflow.db") -> EnterpriseManager:
|
||||||
"""获取 EnterpriseManager 单例"""
|
"""获取 EnterpriseManager 单例"""
|
||||||
global _enterprise_manager
|
global _enterprise_manager
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import numpy as np
|
|||||||
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
|
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
|
||||||
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
|
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EntityEmbedding:
|
class EntityEmbedding:
|
||||||
entity_id: str
|
entity_id: str
|
||||||
@@ -23,7 +22,6 @@ class EntityEmbedding:
|
|||||||
definition: str
|
definition: str
|
||||||
embedding: list[float]
|
embedding: list[float]
|
||||||
|
|
||||||
|
|
||||||
class EntityAligner:
|
class EntityAligner:
|
||||||
"""实体对齐器 - 使用 embedding 进行相似度匹配"""
|
"""实体对齐器 - 使用 embedding 进行相似度匹配"""
|
||||||
|
|
||||||
@@ -303,7 +301,6 @@ class EntityAligner:
|
|||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
# 简单的字符串相似度计算(不使用 embedding)
|
# 简单的字符串相似度计算(不使用 embedding)
|
||||||
def simple_similarity(str1: str, str2: str) -> float:
|
def simple_similarity(str1: str, str2: str) -> float:
|
||||||
"""
|
"""
|
||||||
@@ -335,7 +332,6 @@ def simple_similarity(str1: str, str2: str) -> float:
|
|||||||
|
|
||||||
return SequenceMatcher(None, s1, s2).ratio()
|
return SequenceMatcher(None, s1, s2).ratio()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 测试
|
# 测试
|
||||||
aligner = EntityAligner()
|
aligner = EntityAligner()
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
REPORTLAB_AVAILABLE = False
|
REPORTLAB_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExportEntity:
|
class ExportEntity:
|
||||||
id: str
|
id: str
|
||||||
@@ -40,7 +39,6 @@ class ExportEntity:
|
|||||||
mention_count: int
|
mention_count: int
|
||||||
attributes: dict[str, Any]
|
attributes: dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExportRelation:
|
class ExportRelation:
|
||||||
id: str
|
id: str
|
||||||
@@ -50,7 +48,6 @@ class ExportRelation:
|
|||||||
confidence: float
|
confidence: float
|
||||||
evidence: str
|
evidence: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExportTranscript:
|
class ExportTranscript:
|
||||||
id: str
|
id: str
|
||||||
@@ -60,7 +57,6 @@ class ExportTranscript:
|
|||||||
segments: list[dict]
|
segments: list[dict]
|
||||||
entity_mentions: list[dict]
|
entity_mentions: list[dict]
|
||||||
|
|
||||||
|
|
||||||
class ExportManager:
|
class ExportManager:
|
||||||
"""导出管理器 - 处理各种导出需求"""
|
"""导出管理器 - 处理各种导出需求"""
|
||||||
|
|
||||||
@@ -570,11 +566,9 @@ class ExportManager:
|
|||||||
|
|
||||||
return json.dumps(data, ensure_ascii=False, indent=2)
|
return json.dumps(data, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
|
||||||
# 全局导出管理器实例
|
# 全局导出管理器实例
|
||||||
_export_manager = None
|
_export_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_export_manager(db_manager=None) -> None:
|
def get_export_manager(db_manager=None) -> None:
|
||||||
"""获取导出管理器实例"""
|
"""获取导出管理器实例"""
|
||||||
global _export_manager
|
global _export_manager
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import httpx
|
|||||||
# Database path
|
# Database path
|
||||||
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
||||||
|
|
||||||
|
|
||||||
class EventType(StrEnum):
|
class EventType(StrEnum):
|
||||||
"""事件类型"""
|
"""事件类型"""
|
||||||
|
|
||||||
@@ -44,7 +43,6 @@ class EventType(StrEnum):
|
|||||||
INVITE_ACCEPTED = "invite_accepted" # 接受邀请
|
INVITE_ACCEPTED = "invite_accepted" # 接受邀请
|
||||||
REFERRAL_REWARD = "referral_reward" # 推荐奖励
|
REFERRAL_REWARD = "referral_reward" # 推荐奖励
|
||||||
|
|
||||||
|
|
||||||
class ExperimentStatus(StrEnum):
|
class ExperimentStatus(StrEnum):
|
||||||
"""实验状态"""
|
"""实验状态"""
|
||||||
|
|
||||||
@@ -54,7 +52,6 @@ class ExperimentStatus(StrEnum):
|
|||||||
COMPLETED = "completed" # 已完成
|
COMPLETED = "completed" # 已完成
|
||||||
ARCHIVED = "archived" # 已归档
|
ARCHIVED = "archived" # 已归档
|
||||||
|
|
||||||
|
|
||||||
class TrafficAllocationType(StrEnum):
|
class TrafficAllocationType(StrEnum):
|
||||||
"""流量分配类型"""
|
"""流量分配类型"""
|
||||||
|
|
||||||
@@ -62,7 +59,6 @@ class TrafficAllocationType(StrEnum):
|
|||||||
STRATIFIED = "stratified" # 分层分配
|
STRATIFIED = "stratified" # 分层分配
|
||||||
TARGETED = "targeted" # 定向分配
|
TARGETED = "targeted" # 定向分配
|
||||||
|
|
||||||
|
|
||||||
class EmailTemplateType(StrEnum):
|
class EmailTemplateType(StrEnum):
|
||||||
"""邮件模板类型"""
|
"""邮件模板类型"""
|
||||||
|
|
||||||
@@ -74,7 +70,6 @@ class EmailTemplateType(StrEnum):
|
|||||||
REFERRAL = "referral" # 推荐邀请
|
REFERRAL = "referral" # 推荐邀请
|
||||||
NEWSLETTER = "newsletter" # 新闻通讯
|
NEWSLETTER = "newsletter" # 新闻通讯
|
||||||
|
|
||||||
|
|
||||||
class EmailStatus(StrEnum):
|
class EmailStatus(StrEnum):
|
||||||
"""邮件状态"""
|
"""邮件状态"""
|
||||||
|
|
||||||
@@ -88,7 +83,6 @@ class EmailStatus(StrEnum):
|
|||||||
BOUNCED = "bounced" # 退信
|
BOUNCED = "bounced" # 退信
|
||||||
FAILED = "failed" # 失败
|
FAILED = "failed" # 失败
|
||||||
|
|
||||||
|
|
||||||
class WorkflowTriggerType(StrEnum):
|
class WorkflowTriggerType(StrEnum):
|
||||||
"""工作流触发类型"""
|
"""工作流触发类型"""
|
||||||
|
|
||||||
@@ -100,7 +94,6 @@ class WorkflowTriggerType(StrEnum):
|
|||||||
MILESTONE = "milestone" # 里程碑
|
MILESTONE = "milestone" # 里程碑
|
||||||
CUSTOM_EVENT = "custom_event" # 自定义事件
|
CUSTOM_EVENT = "custom_event" # 自定义事件
|
||||||
|
|
||||||
|
|
||||||
class ReferralStatus(StrEnum):
|
class ReferralStatus(StrEnum):
|
||||||
"""推荐状态"""
|
"""推荐状态"""
|
||||||
|
|
||||||
@@ -109,7 +102,6 @@ class ReferralStatus(StrEnum):
|
|||||||
REWARDED = "rewarded" # 已奖励
|
REWARDED = "rewarded" # 已奖励
|
||||||
EXPIRED = "expired" # 已过期
|
EXPIRED = "expired" # 已过期
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AnalyticsEvent:
|
class AnalyticsEvent:
|
||||||
"""分析事件"""
|
"""分析事件"""
|
||||||
@@ -128,7 +120,6 @@ class AnalyticsEvent:
|
|||||||
utm_medium: str | None
|
utm_medium: str | None
|
||||||
utm_campaign: str | None
|
utm_campaign: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class UserProfile:
|
class UserProfile:
|
||||||
"""用户画像"""
|
"""用户画像"""
|
||||||
@@ -148,7 +139,6 @@ class UserProfile:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Funnel:
|
class Funnel:
|
||||||
"""转化漏斗"""
|
"""转化漏斗"""
|
||||||
@@ -161,7 +151,6 @@ class Funnel:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FunnelAnalysis:
|
class FunnelAnalysis:
|
||||||
"""漏斗分析结果"""
|
"""漏斗分析结果"""
|
||||||
@@ -174,7 +163,6 @@ class FunnelAnalysis:
|
|||||||
overall_conversion: float # 总体转化率
|
overall_conversion: float # 总体转化率
|
||||||
drop_off_points: list[dict] # 流失点
|
drop_off_points: list[dict] # 流失点
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Experiment:
|
class Experiment:
|
||||||
"""A/B 测试实验"""
|
"""A/B 测试实验"""
|
||||||
@@ -199,7 +187,6 @@ class Experiment:
|
|||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
created_by: str
|
created_by: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExperimentResult:
|
class ExperimentResult:
|
||||||
"""实验结果"""
|
"""实验结果"""
|
||||||
@@ -217,7 +204,6 @@ class ExperimentResult:
|
|||||||
uplift: float # 提升幅度
|
uplift: float # 提升幅度
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EmailTemplate:
|
class EmailTemplate:
|
||||||
"""邮件模板"""
|
"""邮件模板"""
|
||||||
@@ -238,7 +224,6 @@ class EmailTemplate:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EmailCampaign:
|
class EmailCampaign:
|
||||||
"""邮件营销活动"""
|
"""邮件营销活动"""
|
||||||
@@ -260,7 +245,6 @@ class EmailCampaign:
|
|||||||
completed_at: datetime | None
|
completed_at: datetime | None
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EmailLog:
|
class EmailLog:
|
||||||
"""邮件发送记录"""
|
"""邮件发送记录"""
|
||||||
@@ -282,7 +266,6 @@ class EmailLog:
|
|||||||
error_message: str | None
|
error_message: str | None
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AutomationWorkflow:
|
class AutomationWorkflow:
|
||||||
"""自动化工作流"""
|
"""自动化工作流"""
|
||||||
@@ -299,7 +282,6 @@ class AutomationWorkflow:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ReferralProgram:
|
class ReferralProgram:
|
||||||
"""推荐计划"""
|
"""推荐计划"""
|
||||||
@@ -319,7 +301,6 @@ class ReferralProgram:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Referral:
|
class Referral:
|
||||||
"""推荐记录"""
|
"""推荐记录"""
|
||||||
@@ -340,7 +321,6 @@ class Referral:
|
|||||||
expires_at: datetime
|
expires_at: datetime
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TeamIncentive:
|
class TeamIncentive:
|
||||||
"""团队升级激励"""
|
"""团队升级激励"""
|
||||||
@@ -358,7 +338,6 @@ class TeamIncentive:
|
|||||||
is_active: bool
|
is_active: bool
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
class GrowthManager:
|
class GrowthManager:
|
||||||
"""运营与增长管理主类"""
|
"""运营与增长管理主类"""
|
||||||
|
|
||||||
@@ -2059,11 +2038,9 @@ class GrowthManager:
|
|||||||
created_at=row["created_at"],
|
created_at=row["created_at"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_growth_manager = None
|
_growth_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_growth_manager() -> GrowthManager:
|
def get_growth_manager() -> GrowthManager:
|
||||||
global _growth_manager
|
global _growth_manager
|
||||||
if _growth_manager is None:
|
if _growth_manager is None:
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
PYTESSERACT_AVAILABLE = False
|
PYTESSERACT_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ImageEntity:
|
class ImageEntity:
|
||||||
"""图片中检测到的实体"""
|
"""图片中检测到的实体"""
|
||||||
@@ -43,7 +42,6 @@ class ImageEntity:
|
|||||||
confidence: float
|
confidence: float
|
||||||
bbox: tuple[int, int, int, int] | None = None # (x, y, width, height)
|
bbox: tuple[int, int, int, int] | None = None # (x, y, width, height)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ImageRelation:
|
class ImageRelation:
|
||||||
"""图片中检测到的关系"""
|
"""图片中检测到的关系"""
|
||||||
@@ -53,7 +51,6 @@ class ImageRelation:
|
|||||||
relation_type: str
|
relation_type: str
|
||||||
confidence: float
|
confidence: float
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ImageProcessingResult:
|
class ImageProcessingResult:
|
||||||
"""图片处理结果"""
|
"""图片处理结果"""
|
||||||
@@ -69,7 +66,6 @@ class ImageProcessingResult:
|
|||||||
success: bool
|
success: bool
|
||||||
error_message: str = ""
|
error_message: str = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BatchProcessingResult:
|
class BatchProcessingResult:
|
||||||
"""批量图片处理结果"""
|
"""批量图片处理结果"""
|
||||||
@@ -79,7 +75,6 @@ class BatchProcessingResult:
|
|||||||
success_count: int
|
success_count: int
|
||||||
failed_count: int
|
failed_count: int
|
||||||
|
|
||||||
|
|
||||||
class ImageProcessor:
|
class ImageProcessor:
|
||||||
"""图片处理器 - 处理各种类型图片"""
|
"""图片处理器 - 处理各种类型图片"""
|
||||||
|
|
||||||
@@ -539,11 +534,9 @@ class ImageProcessor:
|
|||||||
print(f"Thumbnail generation error: {e}")
|
print(f"Thumbnail generation error: {e}")
|
||||||
return image_data
|
return image_data
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_image_processor = None
|
_image_processor = None
|
||||||
|
|
||||||
|
|
||||||
def get_image_processor(temp_dir: str = None) -> ImageProcessor:
|
def get_image_processor(temp_dir: str = None) -> ImageProcessor:
|
||||||
"""获取图片处理器单例"""
|
"""获取图片处理器单例"""
|
||||||
global _image_processor
|
global _image_processor
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import httpx
|
|||||||
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
|
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
|
||||||
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
|
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
|
||||||
|
|
||||||
|
|
||||||
class ReasoningType(Enum):
|
class ReasoningType(Enum):
|
||||||
"""推理类型"""
|
"""推理类型"""
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@ class ReasoningType(Enum):
|
|||||||
COMPARATIVE = "comparative" # 对比推理
|
COMPARATIVE = "comparative" # 对比推理
|
||||||
SUMMARY = "summary" # 总结推理
|
SUMMARY = "summary" # 总结推理
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ReasoningResult:
|
class ReasoningResult:
|
||||||
"""推理结果"""
|
"""推理结果"""
|
||||||
@@ -37,7 +35,6 @@ class ReasoningResult:
|
|||||||
related_entities: list[str] # 相关实体
|
related_entities: list[str] # 相关实体
|
||||||
gaps: list[str] # 知识缺口
|
gaps: list[str] # 知识缺口
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class InferencePath:
|
class InferencePath:
|
||||||
"""推理路径"""
|
"""推理路径"""
|
||||||
@@ -47,7 +44,6 @@ class InferencePath:
|
|||||||
path: list[dict] # 路径上的节点和关系
|
path: list[dict] # 路径上的节点和关系
|
||||||
strength: float # 路径强度
|
strength: float # 路径强度
|
||||||
|
|
||||||
|
|
||||||
class KnowledgeReasoner:
|
class KnowledgeReasoner:
|
||||||
"""知识推理引擎"""
|
"""知识推理引擎"""
|
||||||
|
|
||||||
@@ -484,11 +480,9 @@ class KnowledgeReasoner:
|
|||||||
"confidence": 0.5,
|
"confidence": 0.5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_reasoner = None
|
_reasoner = None
|
||||||
|
|
||||||
|
|
||||||
def get_knowledge_reasoner() -> KnowledgeReasoner:
|
def get_knowledge_reasoner() -> KnowledgeReasoner:
|
||||||
global _reasoner
|
global _reasoner
|
||||||
if _reasoner is None:
|
if _reasoner is None:
|
||||||
|
|||||||
@@ -15,13 +15,11 @@ import httpx
|
|||||||
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
|
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
|
||||||
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
|
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ChatMessage:
|
class ChatMessage:
|
||||||
role: str
|
role: str
|
||||||
content: str
|
content: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EntityExtractionResult:
|
class EntityExtractionResult:
|
||||||
name: str
|
name: str
|
||||||
@@ -29,7 +27,6 @@ class EntityExtractionResult:
|
|||||||
definition: str
|
definition: str
|
||||||
confidence: float
|
confidence: float
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RelationExtractionResult:
|
class RelationExtractionResult:
|
||||||
source: str
|
source: str
|
||||||
@@ -37,7 +34,6 @@ class RelationExtractionResult:
|
|||||||
type: str
|
type: str
|
||||||
confidence: float
|
confidence: float
|
||||||
|
|
||||||
|
|
||||||
class LLMClient:
|
class LLMClient:
|
||||||
"""Kimi API 客户端"""
|
"""Kimi API 客户端"""
|
||||||
|
|
||||||
@@ -236,11 +232,9 @@ class LLMClient:
|
|||||||
messages = [ChatMessage(role="user", content=prompt)]
|
messages = [ChatMessage(role="user", content=prompt)]
|
||||||
return await self.chat(messages, temperature=0.3)
|
return await self.chat(messages, temperature=0.3)
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_llm_client = None
|
_llm_client = None
|
||||||
|
|
||||||
|
|
||||||
def get_llm_client() -> LLMClient:
|
def get_llm_client() -> LLMClient:
|
||||||
global _llm_client
|
global _llm_client
|
||||||
if _llm_client is None:
|
if _llm_client is None:
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ except ImportError:
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LanguageCode(StrEnum):
|
class LanguageCode(StrEnum):
|
||||||
"""支持的语言代码"""
|
"""支持的语言代码"""
|
||||||
|
|
||||||
@@ -52,7 +51,6 @@ class LanguageCode(StrEnum):
|
|||||||
AR = "ar"
|
AR = "ar"
|
||||||
HI = "hi"
|
HI = "hi"
|
||||||
|
|
||||||
|
|
||||||
class RegionCode(StrEnum):
|
class RegionCode(StrEnum):
|
||||||
"""区域代码"""
|
"""区域代码"""
|
||||||
|
|
||||||
@@ -64,7 +62,6 @@ class RegionCode(StrEnum):
|
|||||||
LATIN_AMERICA = "latam"
|
LATIN_AMERICA = "latam"
|
||||||
MIDDLE_EAST = "me"
|
MIDDLE_EAST = "me"
|
||||||
|
|
||||||
|
|
||||||
class DataCenterRegion(StrEnum):
|
class DataCenterRegion(StrEnum):
|
||||||
"""数据中心区域"""
|
"""数据中心区域"""
|
||||||
|
|
||||||
@@ -78,7 +75,6 @@ class DataCenterRegion(StrEnum):
|
|||||||
CN_NORTH = "cn-north"
|
CN_NORTH = "cn-north"
|
||||||
CN_EAST = "cn-east"
|
CN_EAST = "cn-east"
|
||||||
|
|
||||||
|
|
||||||
class PaymentProvider(StrEnum):
|
class PaymentProvider(StrEnum):
|
||||||
"""支付提供商"""
|
"""支付提供商"""
|
||||||
|
|
||||||
@@ -95,7 +91,6 @@ class PaymentProvider(StrEnum):
|
|||||||
SEPA = "sepa"
|
SEPA = "sepa"
|
||||||
UNIONPAY = "unionpay"
|
UNIONPAY = "unionpay"
|
||||||
|
|
||||||
|
|
||||||
class CalendarType(StrEnum):
|
class CalendarType(StrEnum):
|
||||||
"""日历类型"""
|
"""日历类型"""
|
||||||
|
|
||||||
@@ -107,7 +102,6 @@ class CalendarType(StrEnum):
|
|||||||
PERSIAN = "persian"
|
PERSIAN = "persian"
|
||||||
BUDDHIST = "buddhist"
|
BUDDHIST = "buddhist"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Translation:
|
class Translation:
|
||||||
id: str
|
id: str
|
||||||
@@ -122,7 +116,6 @@ class Translation:
|
|||||||
reviewed_by: str | None
|
reviewed_by: str | None
|
||||||
reviewed_at: datetime | None
|
reviewed_at: datetime | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LanguageConfig:
|
class LanguageConfig:
|
||||||
code: str
|
code: str
|
||||||
@@ -140,7 +133,6 @@ class LanguageConfig:
|
|||||||
first_day_of_week: int
|
first_day_of_week: int
|
||||||
calendar_type: str
|
calendar_type: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DataCenter:
|
class DataCenter:
|
||||||
id: str
|
id: str
|
||||||
@@ -155,7 +147,6 @@ class DataCenter:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TenantDataCenterMapping:
|
class TenantDataCenterMapping:
|
||||||
id: str
|
id: str
|
||||||
@@ -167,7 +158,6 @@ class TenantDataCenterMapping:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LocalizedPaymentMethod:
|
class LocalizedPaymentMethod:
|
||||||
id: str
|
id: str
|
||||||
@@ -185,7 +175,6 @@ class LocalizedPaymentMethod:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CountryConfig:
|
class CountryConfig:
|
||||||
code: str
|
code: str
|
||||||
@@ -207,7 +196,6 @@ class CountryConfig:
|
|||||||
vat_rate: float | None
|
vat_rate: float | None
|
||||||
is_active: bool
|
is_active: bool
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TimezoneConfig:
|
class TimezoneConfig:
|
||||||
id: str
|
id: str
|
||||||
@@ -218,7 +206,6 @@ class TimezoneConfig:
|
|||||||
region: str
|
region: str
|
||||||
is_active: bool
|
is_active: bool
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CurrencyConfig:
|
class CurrencyConfig:
|
||||||
code: str
|
code: str
|
||||||
@@ -230,7 +217,6 @@ class CurrencyConfig:
|
|||||||
thousands_separator: str
|
thousands_separator: str
|
||||||
is_active: bool
|
is_active: bool
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LocalizationSettings:
|
class LocalizationSettings:
|
||||||
id: str
|
id: str
|
||||||
@@ -250,7 +236,6 @@ class LocalizationSettings:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
class LocalizationManager:
|
class LocalizationManager:
|
||||||
DEFAULT_LANGUAGES = {
|
DEFAULT_LANGUAGES = {
|
||||||
LanguageCode.EN: {
|
LanguageCode.EN: {
|
||||||
@@ -1604,10 +1589,8 @@ class LocalizationManager:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_localization_manager = None
|
_localization_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_localization_manager(db_path: str = "insightflow.db") -> LocalizationManager:
|
def get_localization_manager(db_path: str = "insightflow.db") -> LocalizationManager:
|
||||||
global _localization_manager
|
global _localization_manager
|
||||||
if _localization_manager is None:
|
if _localization_manager is None:
|
||||||
|
|||||||
714
backend/main.py
714
backend/main.py
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
NUMPY_AVAILABLE = False
|
NUMPY_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MultimodalEntity:
|
class MultimodalEntity:
|
||||||
"""多模态实体"""
|
"""多模态实体"""
|
||||||
@@ -33,7 +32,6 @@ class MultimodalEntity:
|
|||||||
if self.modality_features is None:
|
if self.modality_features is None:
|
||||||
self.modality_features = {}
|
self.modality_features = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EntityLink:
|
class EntityLink:
|
||||||
"""实体关联"""
|
"""实体关联"""
|
||||||
@@ -48,7 +46,6 @@ class EntityLink:
|
|||||||
confidence: float
|
confidence: float
|
||||||
evidence: str
|
evidence: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AlignmentResult:
|
class AlignmentResult:
|
||||||
"""对齐结果"""
|
"""对齐结果"""
|
||||||
@@ -59,7 +56,6 @@ class AlignmentResult:
|
|||||||
match_type: str # exact, fuzzy, embedding
|
match_type: str # exact, fuzzy, embedding
|
||||||
confidence: float
|
confidence: float
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FusionResult:
|
class FusionResult:
|
||||||
"""知识融合结果"""
|
"""知识融合结果"""
|
||||||
@@ -70,7 +66,6 @@ class FusionResult:
|
|||||||
source_modalities: list[str]
|
source_modalities: list[str]
|
||||||
confidence: float
|
confidence: float
|
||||||
|
|
||||||
|
|
||||||
class MultimodalEntityLinker:
|
class MultimodalEntityLinker:
|
||||||
"""多模态实体关联器 - 跨模态实体对齐和知识融合"""
|
"""多模态实体关联器 - 跨模态实体对齐和知识融合"""
|
||||||
|
|
||||||
@@ -497,11 +492,9 @@ class MultimodalEntityLinker:
|
|||||||
"cross_modal_ratio": cross_modal_count / len(entity_modalities) if entity_modalities else 0,
|
"cross_modal_ratio": cross_modal_count / len(entity_modalities) if entity_modalities else 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_multimodal_entity_linker = None
|
_multimodal_entity_linker = None
|
||||||
|
|
||||||
|
|
||||||
def get_multimodal_entity_linker(similarity_threshold: float = 0.85) -> MultimodalEntityLinker:
|
def get_multimodal_entity_linker(similarity_threshold: float = 0.85) -> MultimodalEntityLinker:
|
||||||
"""获取多模态实体关联器单例"""
|
"""获取多模态实体关联器单例"""
|
||||||
global _multimodal_entity_linker
|
global _multimodal_entity_linker
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
FFMPEG_AVAILABLE = False
|
FFMPEG_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class VideoFrame:
|
class VideoFrame:
|
||||||
"""视频关键帧数据类"""
|
"""视频关键帧数据类"""
|
||||||
@@ -53,7 +52,6 @@ class VideoFrame:
|
|||||||
if self.entities_detected is None:
|
if self.entities_detected is None:
|
||||||
self.entities_detected = []
|
self.entities_detected = []
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class VideoInfo:
|
class VideoInfo:
|
||||||
"""视频信息数据类"""
|
"""视频信息数据类"""
|
||||||
@@ -77,7 +75,6 @@ class VideoInfo:
|
|||||||
if self.metadata is None:
|
if self.metadata is None:
|
||||||
self.metadata = {}
|
self.metadata = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class VideoProcessingResult:
|
class VideoProcessingResult:
|
||||||
"""视频处理结果"""
|
"""视频处理结果"""
|
||||||
@@ -90,7 +87,6 @@ class VideoProcessingResult:
|
|||||||
success: bool
|
success: bool
|
||||||
error_message: str = ""
|
error_message: str = ""
|
||||||
|
|
||||||
|
|
||||||
class MultimodalProcessor:
|
class MultimodalProcessor:
|
||||||
"""多模态处理器 - 处理视频文件"""
|
"""多模态处理器 - 处理视频文件"""
|
||||||
|
|
||||||
@@ -425,11 +421,9 @@ class MultimodalProcessor:
|
|||||||
shutil.rmtree(dir_path)
|
shutil.rmtree(dir_path)
|
||||||
os.makedirs(dir_path, exist_ok=True)
|
os.makedirs(dir_path, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_multimodal_processor = None
|
_multimodal_processor = None
|
||||||
|
|
||||||
|
|
||||||
def get_multimodal_processor(temp_dir: str = None, frame_interval: int = 5) -> MultimodalProcessor:
|
def get_multimodal_processor(temp_dir: str = None, frame_interval: int = 5) -> MultimodalProcessor:
|
||||||
"""获取多模态处理器单例"""
|
"""获取多模态处理器单例"""
|
||||||
global _multimodal_processor
|
global _multimodal_processor
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ except ImportError:
|
|||||||
NEO4J_AVAILABLE = False
|
NEO4J_AVAILABLE = False
|
||||||
logger.warning("Neo4j driver not installed. Neo4j features will be disabled.")
|
logger.warning("Neo4j driver not installed. Neo4j features will be disabled.")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class GraphEntity:
|
class GraphEntity:
|
||||||
"""图数据库中的实体节点"""
|
"""图数据库中的实体节点"""
|
||||||
@@ -45,7 +44,6 @@ class GraphEntity:
|
|||||||
if self.properties is None:
|
if self.properties is None:
|
||||||
self.properties = {}
|
self.properties = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class GraphRelation:
|
class GraphRelation:
|
||||||
"""图数据库中的关系边"""
|
"""图数据库中的关系边"""
|
||||||
@@ -61,7 +59,6 @@ class GraphRelation:
|
|||||||
if self.properties is None:
|
if self.properties is None:
|
||||||
self.properties = {}
|
self.properties = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PathResult:
|
class PathResult:
|
||||||
"""路径查询结果"""
|
"""路径查询结果"""
|
||||||
@@ -71,7 +68,6 @@ class PathResult:
|
|||||||
length: int
|
length: int
|
||||||
total_weight: float = 0.0
|
total_weight: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CommunityResult:
|
class CommunityResult:
|
||||||
"""社区发现结果"""
|
"""社区发现结果"""
|
||||||
@@ -81,7 +77,6 @@ class CommunityResult:
|
|||||||
size: int
|
size: int
|
||||||
density: float = 0.0
|
density: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CentralityResult:
|
class CentralityResult:
|
||||||
"""中心性分析结果"""
|
"""中心性分析结果"""
|
||||||
@@ -91,7 +86,6 @@ class CentralityResult:
|
|||||||
score: float
|
score: float
|
||||||
rank: int = 0
|
rank: int = 0
|
||||||
|
|
||||||
|
|
||||||
class Neo4jManager:
|
class Neo4jManager:
|
||||||
"""Neo4j 图数据库管理器"""
|
"""Neo4j 图数据库管理器"""
|
||||||
|
|
||||||
@@ -936,11 +930,9 @@ class Neo4jManager:
|
|||||||
|
|
||||||
return {"nodes": nodes, "relationships": relationships}
|
return {"nodes": nodes, "relationships": relationships}
|
||||||
|
|
||||||
|
|
||||||
# 全局单例
|
# 全局单例
|
||||||
_neo4j_manager = None
|
_neo4j_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_neo4j_manager() -> Neo4jManager:
|
def get_neo4j_manager() -> Neo4jManager:
|
||||||
"""获取 Neo4j 管理器单例"""
|
"""获取 Neo4j 管理器单例"""
|
||||||
global _neo4j_manager
|
global _neo4j_manager
|
||||||
@@ -948,7 +940,6 @@ def get_neo4j_manager() -> Neo4jManager:
|
|||||||
_neo4j_manager = Neo4jManager()
|
_neo4j_manager = Neo4jManager()
|
||||||
return _neo4j_manager
|
return _neo4j_manager
|
||||||
|
|
||||||
|
|
||||||
def close_neo4j_manager() -> None:
|
def close_neo4j_manager() -> None:
|
||||||
"""关闭 Neo4j 连接"""
|
"""关闭 Neo4j 连接"""
|
||||||
global _neo4j_manager
|
global _neo4j_manager
|
||||||
@@ -956,7 +947,6 @@ def close_neo4j_manager() -> None:
|
|||||||
_neo4j_manager.close()
|
_neo4j_manager.close()
|
||||||
_neo4j_manager = None
|
_neo4j_manager = None
|
||||||
|
|
||||||
|
|
||||||
# 便捷函数
|
# 便捷函数
|
||||||
def sync_project_to_neo4j(project_id: str, project_name: str, entities: list[dict], relations: list[dict]) -> None:
|
def sync_project_to_neo4j(project_id: str, project_name: str, entities: list[dict], relations: list[dict]) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -1007,7 +997,6 @@ def sync_project_to_neo4j(project_id: str, project_name: str, entities: list[dic
|
|||||||
|
|
||||||
logger.info(f"Synced project {project_id} to Neo4j: {len(entities)} entities, {len(relations)} relations")
|
logger.info(f"Synced project {project_id} to Neo4j: {len(entities)} entities, {len(relations)} relations")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 测试代码
|
# 测试代码
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import httpx
|
|||||||
# Database path
|
# Database path
|
||||||
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
||||||
|
|
||||||
|
|
||||||
class AlertSeverity(StrEnum):
|
class AlertSeverity(StrEnum):
|
||||||
"""告警严重级别 P0-P3"""
|
"""告警严重级别 P0-P3"""
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@ class AlertSeverity(StrEnum):
|
|||||||
P2 = "p2" # 一般 - 部分功能受影响,需要4小时内处理
|
P2 = "p2" # 一般 - 部分功能受影响,需要4小时内处理
|
||||||
P3 = "p3" # 轻微 - 非核心功能问题,24小时内处理
|
P3 = "p3" # 轻微 - 非核心功能问题,24小时内处理
|
||||||
|
|
||||||
|
|
||||||
class AlertStatus(StrEnum):
|
class AlertStatus(StrEnum):
|
||||||
"""告警状态"""
|
"""告警状态"""
|
||||||
|
|
||||||
@@ -47,7 +45,6 @@ class AlertStatus(StrEnum):
|
|||||||
ACKNOWLEDGED = "acknowledged" # 已确认
|
ACKNOWLEDGED = "acknowledged" # 已确认
|
||||||
SUPPRESSED = "suppressed" # 已抑制
|
SUPPRESSED = "suppressed" # 已抑制
|
||||||
|
|
||||||
|
|
||||||
class AlertChannelType(StrEnum):
|
class AlertChannelType(StrEnum):
|
||||||
"""告警渠道类型"""
|
"""告警渠道类型"""
|
||||||
|
|
||||||
@@ -60,7 +57,6 @@ class AlertChannelType(StrEnum):
|
|||||||
SMS = "sms"
|
SMS = "sms"
|
||||||
WEBHOOK = "webhook"
|
WEBHOOK = "webhook"
|
||||||
|
|
||||||
|
|
||||||
class AlertRuleType(StrEnum):
|
class AlertRuleType(StrEnum):
|
||||||
"""告警规则类型"""
|
"""告警规则类型"""
|
||||||
|
|
||||||
@@ -69,7 +65,6 @@ class AlertRuleType(StrEnum):
|
|||||||
PREDICTIVE = "predictive" # 预测性告警
|
PREDICTIVE = "predictive" # 预测性告警
|
||||||
COMPOSITE = "composite" # 复合告警
|
COMPOSITE = "composite" # 复合告警
|
||||||
|
|
||||||
|
|
||||||
class ResourceType(StrEnum):
|
class ResourceType(StrEnum):
|
||||||
"""资源类型"""
|
"""资源类型"""
|
||||||
|
|
||||||
@@ -82,7 +77,6 @@ class ResourceType(StrEnum):
|
|||||||
CACHE = "cache"
|
CACHE = "cache"
|
||||||
QUEUE = "queue"
|
QUEUE = "queue"
|
||||||
|
|
||||||
|
|
||||||
class ScalingAction(StrEnum):
|
class ScalingAction(StrEnum):
|
||||||
"""扩缩容动作"""
|
"""扩缩容动作"""
|
||||||
|
|
||||||
@@ -90,7 +84,6 @@ class ScalingAction(StrEnum):
|
|||||||
SCALE_DOWN = "scale_down" # 缩容
|
SCALE_DOWN = "scale_down" # 缩容
|
||||||
MAINTAIN = "maintain" # 保持
|
MAINTAIN = "maintain" # 保持
|
||||||
|
|
||||||
|
|
||||||
class HealthStatus(StrEnum):
|
class HealthStatus(StrEnum):
|
||||||
"""健康状态"""
|
"""健康状态"""
|
||||||
|
|
||||||
@@ -99,7 +92,6 @@ class HealthStatus(StrEnum):
|
|||||||
UNHEALTHY = "unhealthy"
|
UNHEALTHY = "unhealthy"
|
||||||
UNKNOWN = "unknown"
|
UNKNOWN = "unknown"
|
||||||
|
|
||||||
|
|
||||||
class BackupStatus(StrEnum):
|
class BackupStatus(StrEnum):
|
||||||
"""备份状态"""
|
"""备份状态"""
|
||||||
|
|
||||||
@@ -109,7 +101,6 @@ class BackupStatus(StrEnum):
|
|||||||
FAILED = "failed"
|
FAILED = "failed"
|
||||||
VERIFIED = "verified"
|
VERIFIED = "verified"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AlertRule:
|
class AlertRule:
|
||||||
"""告警规则"""
|
"""告警规则"""
|
||||||
@@ -133,7 +124,6 @@ class AlertRule:
|
|||||||
updated_at: str
|
updated_at: str
|
||||||
created_by: str
|
created_by: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AlertChannel:
|
class AlertChannel:
|
||||||
"""告警渠道配置"""
|
"""告警渠道配置"""
|
||||||
@@ -151,7 +141,6 @@ class AlertChannel:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Alert:
|
class Alert:
|
||||||
"""告警实例"""
|
"""告警实例"""
|
||||||
@@ -175,7 +164,6 @@ class Alert:
|
|||||||
notification_sent: dict[str, bool] # 渠道发送状态
|
notification_sent: dict[str, bool] # 渠道发送状态
|
||||||
suppression_count: int # 抑制计数
|
suppression_count: int # 抑制计数
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AlertSuppressionRule:
|
class AlertSuppressionRule:
|
||||||
"""告警抑制规则"""
|
"""告警抑制规则"""
|
||||||
@@ -189,7 +177,6 @@ class AlertSuppressionRule:
|
|||||||
created_at: str
|
created_at: str
|
||||||
expires_at: str | None
|
expires_at: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AlertGroup:
|
class AlertGroup:
|
||||||
"""告警聚合组"""
|
"""告警聚合组"""
|
||||||
@@ -201,7 +188,6 @@ class AlertGroup:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ResourceMetric:
|
class ResourceMetric:
|
||||||
"""资源指标"""
|
"""资源指标"""
|
||||||
@@ -216,7 +202,6 @@ class ResourceMetric:
|
|||||||
timestamp: str
|
timestamp: str
|
||||||
metadata: dict
|
metadata: dict
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CapacityPlan:
|
class CapacityPlan:
|
||||||
"""容量规划"""
|
"""容量规划"""
|
||||||
@@ -232,7 +217,6 @@ class CapacityPlan:
|
|||||||
estimated_cost: float
|
estimated_cost: float
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AutoScalingPolicy:
|
class AutoScalingPolicy:
|
||||||
"""自动扩缩容策略"""
|
"""自动扩缩容策略"""
|
||||||
@@ -253,7 +237,6 @@ class AutoScalingPolicy:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ScalingEvent:
|
class ScalingEvent:
|
||||||
"""扩缩容事件"""
|
"""扩缩容事件"""
|
||||||
@@ -271,7 +254,6 @@ class ScalingEvent:
|
|||||||
completed_at: str | None
|
completed_at: str | None
|
||||||
error_message: str | None
|
error_message: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HealthCheck:
|
class HealthCheck:
|
||||||
"""健康检查配置"""
|
"""健康检查配置"""
|
||||||
@@ -292,7 +274,6 @@ class HealthCheck:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HealthCheckResult:
|
class HealthCheckResult:
|
||||||
"""健康检查结果"""
|
"""健康检查结果"""
|
||||||
@@ -306,7 +287,6 @@ class HealthCheckResult:
|
|||||||
details: dict
|
details: dict
|
||||||
checked_at: str
|
checked_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FailoverConfig:
|
class FailoverConfig:
|
||||||
"""故障转移配置"""
|
"""故障转移配置"""
|
||||||
@@ -324,7 +304,6 @@ class FailoverConfig:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FailoverEvent:
|
class FailoverEvent:
|
||||||
"""故障转移事件"""
|
"""故障转移事件"""
|
||||||
@@ -340,7 +319,6 @@ class FailoverEvent:
|
|||||||
completed_at: str | None
|
completed_at: str | None
|
||||||
rolled_back_at: str | None
|
rolled_back_at: str | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BackupJob:
|
class BackupJob:
|
||||||
"""备份任务"""
|
"""备份任务"""
|
||||||
@@ -360,7 +338,6 @@ class BackupJob:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BackupRecord:
|
class BackupRecord:
|
||||||
"""备份记录"""
|
"""备份记录"""
|
||||||
@@ -377,7 +354,6 @@ class BackupRecord:
|
|||||||
error_message: str | None
|
error_message: str | None
|
||||||
storage_path: str
|
storage_path: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CostReport:
|
class CostReport:
|
||||||
"""成本报告"""
|
"""成本报告"""
|
||||||
@@ -392,7 +368,6 @@ class CostReport:
|
|||||||
anomalies: list[dict] # 异常检测
|
anomalies: list[dict] # 异常检测
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ResourceUtilization:
|
class ResourceUtilization:
|
||||||
"""资源利用率"""
|
"""资源利用率"""
|
||||||
@@ -408,7 +383,6 @@ class ResourceUtilization:
|
|||||||
report_date: str
|
report_date: str
|
||||||
recommendations: list[str]
|
recommendations: list[str]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class IdleResource:
|
class IdleResource:
|
||||||
"""闲置资源"""
|
"""闲置资源"""
|
||||||
@@ -425,7 +399,6 @@ class IdleResource:
|
|||||||
recommendation: str
|
recommendation: str
|
||||||
detected_at: str
|
detected_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CostOptimizationSuggestion:
|
class CostOptimizationSuggestion:
|
||||||
"""成本优化建议"""
|
"""成本优化建议"""
|
||||||
@@ -445,7 +418,6 @@ class CostOptimizationSuggestion:
|
|||||||
created_at: str
|
created_at: str
|
||||||
applied_at: str | None
|
applied_at: str | None
|
||||||
|
|
||||||
|
|
||||||
class OpsManager:
|
class OpsManager:
|
||||||
"""运维与监控管理主类"""
|
"""运维与监控管理主类"""
|
||||||
|
|
||||||
@@ -3008,11 +2980,9 @@ class OpsManager:
|
|||||||
applied_at=row["applied_at"],
|
applied_at=row["applied_at"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_ops_manager = None
|
_ops_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_ops_manager() -> OpsManager:
|
def get_ops_manager() -> OpsManager:
|
||||||
global _ops_manager
|
global _ops_manager
|
||||||
if _ops_manager is None:
|
if _ops_manager is None:
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from datetime import datetime
|
|||||||
|
|
||||||
import oss2
|
import oss2
|
||||||
|
|
||||||
|
|
||||||
class OSSUploader:
|
class OSSUploader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.access_key = os.getenv("ALI_ACCESS_KEY")
|
self.access_key = os.getenv("ALI_ACCESS_KEY")
|
||||||
@@ -41,11 +40,9 @@ class OSSUploader:
|
|||||||
"""删除 OSS 对象"""
|
"""删除 OSS 对象"""
|
||||||
self.bucket.delete_object(object_name)
|
self.bucket.delete_object(object_name)
|
||||||
|
|
||||||
|
|
||||||
# 单例
|
# 单例
|
||||||
_oss_uploader = None
|
_oss_uploader = None
|
||||||
|
|
||||||
|
|
||||||
def get_oss_uploader() -> OSSUploader:
|
def get_oss_uploader() -> OSSUploader:
|
||||||
global _oss_uploader
|
global _oss_uploader
|
||||||
if _oss_uploader is None:
|
if _oss_uploader is None:
|
||||||
|
|||||||
@@ -40,10 +40,8 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
CELERY_AVAILABLE = False
|
CELERY_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
# ==================== 数据模型 ====================
|
# ==================== 数据模型 ====================
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CacheStats:
|
class CacheStats:
|
||||||
"""缓存统计数据模型"""
|
"""缓存统计数据模型"""
|
||||||
@@ -60,7 +58,6 @@ class CacheStats:
|
|||||||
if self.total_requests > 0:
|
if self.total_requests > 0:
|
||||||
self.hit_rate = round(self.hits / self.total_requests, 4)
|
self.hit_rate = round(self.hits / self.total_requests, 4)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CacheEntry:
|
class CacheEntry:
|
||||||
"""缓存条目数据模型"""
|
"""缓存条目数据模型"""
|
||||||
@@ -73,7 +70,6 @@ class CacheEntry:
|
|||||||
last_accessed: float = 0
|
last_accessed: float = 0
|
||||||
size_bytes: int = 0
|
size_bytes: int = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PerformanceMetric:
|
class PerformanceMetric:
|
||||||
"""性能指标数据模型"""
|
"""性能指标数据模型"""
|
||||||
@@ -95,7 +91,6 @@ class PerformanceMetric:
|
|||||||
"metadata": self.metadata,
|
"metadata": self.metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TaskInfo:
|
class TaskInfo:
|
||||||
"""任务信息数据模型"""
|
"""任务信息数据模型"""
|
||||||
@@ -127,7 +122,6 @@ class TaskInfo:
|
|||||||
"max_retries": self.max_retries,
|
"max_retries": self.max_retries,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ShardInfo:
|
class ShardInfo:
|
||||||
"""分片信息数据模型"""
|
"""分片信息数据模型"""
|
||||||
@@ -140,10 +134,8 @@ class ShardInfo:
|
|||||||
created_at: str = ""
|
created_at: str = ""
|
||||||
last_accessed: str = ""
|
last_accessed: str = ""
|
||||||
|
|
||||||
|
|
||||||
# ==================== Redis 缓存层 ====================
|
# ==================== Redis 缓存层 ====================
|
||||||
|
|
||||||
|
|
||||||
class CacheManager:
|
class CacheManager:
|
||||||
"""
|
"""
|
||||||
缓存管理器
|
缓存管理器
|
||||||
@@ -589,10 +581,8 @@ class CacheManager:
|
|||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
# ==================== 数据库分片 ====================
|
# ==================== 数据库分片 ====================
|
||||||
|
|
||||||
|
|
||||||
class DatabaseSharding:
|
class DatabaseSharding:
|
||||||
"""
|
"""
|
||||||
数据库分片管理器
|
数据库分片管理器
|
||||||
@@ -885,10 +875,8 @@ class DatabaseSharding:
|
|||||||
"message": "Rebalancing analysis completed",
|
"message": "Rebalancing analysis completed",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ==================== 异步任务队列 ====================
|
# ==================== 异步任务队列 ====================
|
||||||
|
|
||||||
|
|
||||||
class TaskQueue:
|
class TaskQueue:
|
||||||
"""
|
"""
|
||||||
异步任务队列管理器
|
异步任务队列管理器
|
||||||
@@ -1266,10 +1254,8 @@ class TaskQueue:
|
|||||||
"backend": "celery" if self.use_celery else "memory",
|
"backend": "celery" if self.use_celery else "memory",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ==================== 性能监控 ====================
|
# ==================== 性能监控 ====================
|
||||||
|
|
||||||
|
|
||||||
class PerformanceMonitor:
|
class PerformanceMonitor:
|
||||||
"""
|
"""
|
||||||
性能监控器
|
性能监控器
|
||||||
@@ -1579,10 +1565,8 @@ class PerformanceMonitor:
|
|||||||
|
|
||||||
return deleted
|
return deleted
|
||||||
|
|
||||||
|
|
||||||
# ==================== 性能装饰器 ====================
|
# ==================== 性能装饰器 ====================
|
||||||
|
|
||||||
|
|
||||||
def cached(
|
def cached(
|
||||||
cache_manager: CacheManager, key_prefix: str = "", ttl: int = 3600, key_func: Callable | None = None
|
cache_manager: CacheManager, key_prefix: str = "", ttl: int = 3600, key_func: Callable | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -1624,7 +1608,6 @@ def cached(
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def monitored(monitor: PerformanceMonitor, metric_type: str, endpoint: str | None = None) -> None:
|
def monitored(monitor: PerformanceMonitor, metric_type: str, endpoint: str | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
性能监控装饰器
|
性能监控装饰器
|
||||||
@@ -1652,10 +1635,8 @@ def monitored(monitor: PerformanceMonitor, metric_type: str, endpoint: str | Non
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
# ==================== 性能管理器 ====================
|
# ==================== 性能管理器 ====================
|
||||||
|
|
||||||
|
|
||||||
class PerformanceManager:
|
class PerformanceManager:
|
||||||
"""
|
"""
|
||||||
性能管理器 - 统一入口
|
性能管理器 - 统一入口
|
||||||
@@ -1712,11 +1693,9 @@ class PerformanceManager:
|
|||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
# 单例模式
|
# 单例模式
|
||||||
_performance_manager = None
|
_performance_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_performance_manager(
|
def get_performance_manager(
|
||||||
db_path: str = "insightflow.db", redis_url: str | None = None, enable_sharding: bool = False
|
db_path: str = "insightflow.db", redis_url: str | None = None, enable_sharding: bool = False
|
||||||
) -> PerformanceManager:
|
) -> PerformanceManager:
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
WEBDAV_AVAILABLE = False
|
WEBDAV_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
class PluginType(Enum):
|
class PluginType(Enum):
|
||||||
"""插件类型"""
|
"""插件类型"""
|
||||||
|
|
||||||
@@ -40,7 +39,6 @@ class PluginType(Enum):
|
|||||||
WEBDAV = "webdav"
|
WEBDAV = "webdav"
|
||||||
CUSTOM = "custom"
|
CUSTOM = "custom"
|
||||||
|
|
||||||
|
|
||||||
class PluginStatus(Enum):
|
class PluginStatus(Enum):
|
||||||
"""插件状态"""
|
"""插件状态"""
|
||||||
|
|
||||||
@@ -49,7 +47,6 @@ class PluginStatus(Enum):
|
|||||||
ERROR = "error"
|
ERROR = "error"
|
||||||
PENDING = "pending"
|
PENDING = "pending"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Plugin:
|
class Plugin:
|
||||||
"""插件配置"""
|
"""插件配置"""
|
||||||
@@ -65,7 +62,6 @@ class Plugin:
|
|||||||
last_used_at: str | None = None
|
last_used_at: str | None = None
|
||||||
use_count: int = 0
|
use_count: int = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PluginConfig:
|
class PluginConfig:
|
||||||
"""插件详细配置"""
|
"""插件详细配置"""
|
||||||
@@ -78,7 +74,6 @@ class PluginConfig:
|
|||||||
created_at: str = ""
|
created_at: str = ""
|
||||||
updated_at: str = ""
|
updated_at: str = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BotSession:
|
class BotSession:
|
||||||
"""机器人会话"""
|
"""机器人会话"""
|
||||||
@@ -96,7 +91,6 @@ class BotSession:
|
|||||||
last_message_at: str | None = None
|
last_message_at: str | None = None
|
||||||
message_count: int = 0
|
message_count: int = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WebhookEndpoint:
|
class WebhookEndpoint:
|
||||||
"""Webhook 端点配置(Zapier/Make集成)"""
|
"""Webhook 端点配置(Zapier/Make集成)"""
|
||||||
@@ -115,7 +109,6 @@ class WebhookEndpoint:
|
|||||||
last_triggered_at: str | None = None
|
last_triggered_at: str | None = None
|
||||||
trigger_count: int = 0
|
trigger_count: int = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WebDAVSync:
|
class WebDAVSync:
|
||||||
"""WebDAV 同步配置"""
|
"""WebDAV 同步配置"""
|
||||||
@@ -137,7 +130,6 @@ class WebDAVSync:
|
|||||||
updated_at: str = ""
|
updated_at: str = ""
|
||||||
sync_count: int = 0
|
sync_count: int = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ChromeExtensionToken:
|
class ChromeExtensionToken:
|
||||||
"""Chrome 扩展令牌"""
|
"""Chrome 扩展令牌"""
|
||||||
@@ -154,7 +146,6 @@ class ChromeExtensionToken:
|
|||||||
use_count: int = 0
|
use_count: int = 0
|
||||||
is_revoked: bool = False
|
is_revoked: bool = False
|
||||||
|
|
||||||
|
|
||||||
class PluginManager:
|
class PluginManager:
|
||||||
"""插件管理主类"""
|
"""插件管理主类"""
|
||||||
|
|
||||||
@@ -385,7 +376,6 @@ class PluginManager:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
class ChromeExtensionHandler:
|
class ChromeExtensionHandler:
|
||||||
"""Chrome 扩展处理器"""
|
"""Chrome 扩展处理器"""
|
||||||
|
|
||||||
@@ -579,7 +569,6 @@ class ChromeExtensionHandler:
|
|||||||
"content_length": len(content),
|
"content_length": len(content),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BotHandler:
|
class BotHandler:
|
||||||
"""飞书/钉钉机器人处理器"""
|
"""飞书/钉钉机器人处理器"""
|
||||||
|
|
||||||
@@ -871,7 +860,6 @@ class BotHandler:
|
|||||||
response = await client.post(url, json=payload, headers={"Content-Type": "application/json"})
|
response = await client.post(url, json=payload, headers={"Content-Type": "application/json"})
|
||||||
return response.status_code == 200
|
return response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
class WebhookIntegration:
|
class WebhookIntegration:
|
||||||
"""Zapier/Make Webhook 集成"""
|
"""Zapier/Make Webhook 集成"""
|
||||||
|
|
||||||
@@ -1091,7 +1079,6 @@ class WebhookIntegration:
|
|||||||
"message": "Test event sent successfully" if success else "Failed to send test event",
|
"message": "Test event sent successfully" if success else "Failed to send test event",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class WebDAVSyncManager:
|
class WebDAVSyncManager:
|
||||||
"""WebDAV 同步管理"""
|
"""WebDAV 同步管理"""
|
||||||
|
|
||||||
@@ -1347,11 +1334,9 @@ class WebDAVSyncManager:
|
|||||||
|
|
||||||
return {"success": False, "error": str(e)}
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_plugin_manager = None
|
_plugin_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_plugin_manager(db_manager=None) -> None:
|
def get_plugin_manager(db_manager=None) -> None:
|
||||||
"""获取 PluginManager 单例"""
|
"""获取 PluginManager 单例"""
|
||||||
global _plugin_manager
|
global _plugin_manager
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from collections.abc import Callable
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RateLimitConfig:
|
class RateLimitConfig:
|
||||||
"""限流配置"""
|
"""限流配置"""
|
||||||
@@ -21,7 +20,6 @@ class RateLimitConfig:
|
|||||||
burst_size: int = 10 # 突发请求数
|
burst_size: int = 10 # 突发请求数
|
||||||
window_size: int = 60 # 窗口大小(秒)
|
window_size: int = 60 # 窗口大小(秒)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RateLimitInfo:
|
class RateLimitInfo:
|
||||||
"""限流信息"""
|
"""限流信息"""
|
||||||
@@ -31,7 +29,6 @@ class RateLimitInfo:
|
|||||||
reset_time: int # 重置时间戳
|
reset_time: int # 重置时间戳
|
||||||
retry_after: int # 需要等待的秒数
|
retry_after: int # 需要等待的秒数
|
||||||
|
|
||||||
|
|
||||||
class SlidingWindowCounter:
|
class SlidingWindowCounter:
|
||||||
"""滑动窗口计数器"""
|
"""滑动窗口计数器"""
|
||||||
|
|
||||||
@@ -63,7 +60,6 @@ class SlidingWindowCounter:
|
|||||||
for k in old_keys:
|
for k in old_keys:
|
||||||
self.requests.pop(k, None)
|
self.requests.pop(k, None)
|
||||||
|
|
||||||
|
|
||||||
class RateLimiter:
|
class RateLimiter:
|
||||||
"""API 限流器"""
|
"""API 限流器"""
|
||||||
|
|
||||||
@@ -152,11 +148,9 @@ class RateLimiter:
|
|||||||
self.counters.clear()
|
self.counters.clear()
|
||||||
self.configs.clear()
|
self.configs.clear()
|
||||||
|
|
||||||
|
|
||||||
# 全局限流器实例
|
# 全局限流器实例
|
||||||
_rate_limiter: RateLimiter | None = None
|
_rate_limiter: RateLimiter | None = None
|
||||||
|
|
||||||
|
|
||||||
def get_rate_limiter() -> RateLimiter:
|
def get_rate_limiter() -> RateLimiter:
|
||||||
"""获取限流器实例"""
|
"""获取限流器实例"""
|
||||||
global _rate_limiter
|
global _rate_limiter
|
||||||
@@ -164,7 +158,6 @@ def get_rate_limiter() -> RateLimiter:
|
|||||||
_rate_limiter = RateLimiter()
|
_rate_limiter = RateLimiter()
|
||||||
return _rate_limiter
|
return _rate_limiter
|
||||||
|
|
||||||
|
|
||||||
# 限流装饰器(用于函数级别限流)
|
# 限流装饰器(用于函数级别限流)
|
||||||
def rate_limit(requests_per_minute: int = 60, key_func: Callable | None = None) -> None:
|
def rate_limit(requests_per_minute: int = 60, key_func: Callable | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -204,6 +197,5 @@ def rate_limit(requests_per_minute: int = 60, key_func: Callable | None = None)
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
class RateLimitExceeded(Exception):
|
class RateLimitExceeded(Exception):
|
||||||
"""限流异常"""
|
"""限流异常"""
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from dataclasses import dataclass, field
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
class SearchOperator(Enum):
|
class SearchOperator(Enum):
|
||||||
"""搜索操作符"""
|
"""搜索操作符"""
|
||||||
|
|
||||||
@@ -27,7 +26,6 @@ class SearchOperator(Enum):
|
|||||||
OR = "OR"
|
OR = "OR"
|
||||||
NOT = "NOT"
|
NOT = "NOT"
|
||||||
|
|
||||||
|
|
||||||
# 尝试导入 sentence-transformers 用于语义搜索
|
# 尝试导入 sentence-transformers 用于语义搜索
|
||||||
try:
|
try:
|
||||||
from sentence_transformers import SentenceTransformer
|
from sentence_transformers import SentenceTransformer
|
||||||
@@ -39,7 +37,6 @@ except ImportError:
|
|||||||
|
|
||||||
# ==================== 数据模型 ====================
|
# ==================== 数据模型 ====================
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SearchResult:
|
class SearchResult:
|
||||||
"""搜索结果数据模型"""
|
"""搜索结果数据模型"""
|
||||||
@@ -63,7 +60,6 @@ class SearchResult:
|
|||||||
"metadata": self.metadata,
|
"metadata": self.metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SemanticSearchResult:
|
class SemanticSearchResult:
|
||||||
"""语义搜索结果数据模型"""
|
"""语义搜索结果数据模型"""
|
||||||
@@ -89,7 +85,6 @@ class SemanticSearchResult:
|
|||||||
result["embedding_dim"] = len(self.embedding)
|
result["embedding_dim"] = len(self.embedding)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EntityPath:
|
class EntityPath:
|
||||||
"""实体关系路径数据模型"""
|
"""实体关系路径数据模型"""
|
||||||
@@ -119,7 +114,6 @@ class EntityPath:
|
|||||||
"path_description": self.path_description,
|
"path_description": self.path_description,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class KnowledgeGap:
|
class KnowledgeGap:
|
||||||
"""知识缺口数据模型"""
|
"""知识缺口数据模型"""
|
||||||
@@ -147,7 +141,6 @@ class KnowledgeGap:
|
|||||||
"metadata": self.metadata,
|
"metadata": self.metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SearchIndex:
|
class SearchIndex:
|
||||||
"""搜索索引数据模型"""
|
"""搜索索引数据模型"""
|
||||||
@@ -161,7 +154,6 @@ class SearchIndex:
|
|||||||
created_at: str
|
created_at: str
|
||||||
updated_at: str
|
updated_at: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TextEmbedding:
|
class TextEmbedding:
|
||||||
"""文本 Embedding 数据模型"""
|
"""文本 Embedding 数据模型"""
|
||||||
@@ -174,10 +166,8 @@ class TextEmbedding:
|
|||||||
model_name: str
|
model_name: str
|
||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
# ==================== 全文搜索 ====================
|
# ==================== 全文搜索 ====================
|
||||||
|
|
||||||
|
|
||||||
class FullTextSearch:
|
class FullTextSearch:
|
||||||
"""
|
"""
|
||||||
全文搜索模块
|
全文搜索模块
|
||||||
@@ -753,10 +743,8 @@ class FullTextSearch:
|
|||||||
conn.close()
|
conn.close()
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
# ==================== 语义搜索 ====================
|
# ==================== 语义搜索 ====================
|
||||||
|
|
||||||
|
|
||||||
class SemanticSearch:
|
class SemanticSearch:
|
||||||
"""
|
"""
|
||||||
语义搜索模块
|
语义搜索模块
|
||||||
@@ -1096,10 +1084,8 @@ class SemanticSearch:
|
|||||||
print(f"删除 embedding 失败: {e}")
|
print(f"删除 embedding 失败: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# ==================== 实体关系路径发现 ====================
|
# ==================== 实体关系路径发现 ====================
|
||||||
|
|
||||||
|
|
||||||
class EntityPathDiscovery:
|
class EntityPathDiscovery:
|
||||||
"""
|
"""
|
||||||
实体关系路径发现模块
|
实体关系路径发现模块
|
||||||
@@ -1555,10 +1541,8 @@ class EntityPathDiscovery:
|
|||||||
bridge_scores.sort(key=lambda x: x["bridge_score"], reverse=True)
|
bridge_scores.sort(key=lambda x: x["bridge_score"], reverse=True)
|
||||||
return bridge_scores[:20] # 返回前20
|
return bridge_scores[:20] # 返回前20
|
||||||
|
|
||||||
|
|
||||||
# ==================== 知识缺口识别 ====================
|
# ==================== 知识缺口识别 ====================
|
||||||
|
|
||||||
|
|
||||||
class KnowledgeGapDetection:
|
class KnowledgeGapDetection:
|
||||||
"""
|
"""
|
||||||
知识缺口识别模块
|
知识缺口识别模块
|
||||||
@@ -1945,10 +1929,8 @@ class KnowledgeGapDetection:
|
|||||||
|
|
||||||
return recommendations
|
return recommendations
|
||||||
|
|
||||||
|
|
||||||
# ==================== 搜索管理器 ====================
|
# ==================== 搜索管理器 ====================
|
||||||
|
|
||||||
|
|
||||||
class SearchManager:
|
class SearchManager:
|
||||||
"""
|
"""
|
||||||
搜索管理器 - 统一入口
|
搜索管理器 - 统一入口
|
||||||
@@ -2119,11 +2101,9 @@ class SearchManager:
|
|||||||
"semantic_search_available": self.semantic_search.is_available(),
|
"semantic_search_available": self.semantic_search.is_available(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# 单例模式
|
# 单例模式
|
||||||
_search_manager = None
|
_search_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_search_manager(db_path: str = "insightflow.db") -> SearchManager:
|
def get_search_manager(db_path: str = "insightflow.db") -> SearchManager:
|
||||||
"""获取搜索管理器单例"""
|
"""获取搜索管理器单例"""
|
||||||
global _search_manager
|
global _search_manager
|
||||||
@@ -2131,26 +2111,22 @@ def get_search_manager(db_path: str = "insightflow.db") -> SearchManager:
|
|||||||
_search_manager = SearchManager(db_path)
|
_search_manager = SearchManager(db_path)
|
||||||
return _search_manager
|
return _search_manager
|
||||||
|
|
||||||
|
|
||||||
# 便捷函数
|
# 便捷函数
|
||||||
def fulltext_search(query: str, project_id: str | None = None, limit: int = 20) -> list[SearchResult]:
|
def fulltext_search(query: str, project_id: str | None = None, limit: int = 20) -> list[SearchResult]:
|
||||||
"""全文搜索便捷函数"""
|
"""全文搜索便捷函数"""
|
||||||
manager = get_search_manager()
|
manager = get_search_manager()
|
||||||
return manager.fulltext_search.search(query, project_id, limit=limit)
|
return manager.fulltext_search.search(query, project_id, limit=limit)
|
||||||
|
|
||||||
|
|
||||||
def semantic_search(query: str, project_id: str | None = None, top_k: int = 10) -> list[SemanticSearchResult]:
|
def semantic_search(query: str, project_id: str | None = None, top_k: int = 10) -> list[SemanticSearchResult]:
|
||||||
"""语义搜索便捷函数"""
|
"""语义搜索便捷函数"""
|
||||||
manager = get_search_manager()
|
manager = get_search_manager()
|
||||||
return manager.semantic_search.search(query, project_id, top_k=top_k)
|
return manager.semantic_search.search(query, project_id, top_k=top_k)
|
||||||
|
|
||||||
|
|
||||||
def find_entity_path(source_id: str, target_id: str, max_depth: int = 5) -> EntityPath | None:
|
def find_entity_path(source_id: str, target_id: str, max_depth: int = 5) -> EntityPath | None:
|
||||||
"""查找实体路径便捷函数"""
|
"""查找实体路径便捷函数"""
|
||||||
manager = get_search_manager()
|
manager = get_search_manager()
|
||||||
return manager.path_discovery.find_shortest_path(source_id, target_id, max_depth)
|
return manager.path_discovery.find_shortest_path(source_id, target_id, max_depth)
|
||||||
|
|
||||||
|
|
||||||
def detect_knowledge_gaps(project_id: str) -> list[KnowledgeGap]:
|
def detect_knowledge_gaps(project_id: str) -> list[KnowledgeGap]:
|
||||||
"""知识缺口检测便捷函数"""
|
"""知识缺口检测便捷函数"""
|
||||||
manager = get_search_manager()
|
manager = get_search_manager()
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ except ImportError:
|
|||||||
CRYPTO_AVAILABLE = False
|
CRYPTO_AVAILABLE = False
|
||||||
print("Warning: cryptography not available, encryption features disabled")
|
print("Warning: cryptography not available, encryption features disabled")
|
||||||
|
|
||||||
|
|
||||||
class AuditActionType(Enum):
|
class AuditActionType(Enum):
|
||||||
"""审计动作类型"""
|
"""审计动作类型"""
|
||||||
|
|
||||||
@@ -48,7 +47,6 @@ class AuditActionType(Enum):
|
|||||||
WEBHOOK_SEND = "webhook_send"
|
WEBHOOK_SEND = "webhook_send"
|
||||||
BOT_MESSAGE = "bot_message"
|
BOT_MESSAGE = "bot_message"
|
||||||
|
|
||||||
|
|
||||||
class DataSensitivityLevel(Enum):
|
class DataSensitivityLevel(Enum):
|
||||||
"""数据敏感度级别"""
|
"""数据敏感度级别"""
|
||||||
|
|
||||||
@@ -57,7 +55,6 @@ class DataSensitivityLevel(Enum):
|
|||||||
CONFIDENTIAL = "confidential" # 机密
|
CONFIDENTIAL = "confidential" # 机密
|
||||||
SECRET = "secret" # 绝密
|
SECRET = "secret" # 绝密
|
||||||
|
|
||||||
|
|
||||||
class MaskingRuleType(Enum):
|
class MaskingRuleType(Enum):
|
||||||
"""脱敏规则类型"""
|
"""脱敏规则类型"""
|
||||||
|
|
||||||
@@ -69,7 +66,6 @@ class MaskingRuleType(Enum):
|
|||||||
ADDRESS = "address" # 地址
|
ADDRESS = "address" # 地址
|
||||||
CUSTOM = "custom" # 自定义
|
CUSTOM = "custom" # 自定义
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AuditLog:
|
class AuditLog:
|
||||||
"""审计日志条目"""
|
"""审计日志条目"""
|
||||||
@@ -91,7 +87,6 @@ class AuditLog:
|
|||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return asdict(self)
|
return asdict(self)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EncryptionConfig:
|
class EncryptionConfig:
|
||||||
"""加密配置"""
|
"""加密配置"""
|
||||||
@@ -109,7 +104,6 @@ class EncryptionConfig:
|
|||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return asdict(self)
|
return asdict(self)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MaskingRule:
|
class MaskingRule:
|
||||||
"""脱敏规则"""
|
"""脱敏规则"""
|
||||||
@@ -129,7 +123,6 @@ class MaskingRule:
|
|||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return asdict(self)
|
return asdict(self)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DataAccessPolicy:
|
class DataAccessPolicy:
|
||||||
"""数据访问策略"""
|
"""数据访问策略"""
|
||||||
@@ -151,7 +144,6 @@ class DataAccessPolicy:
|
|||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return asdict(self)
|
return asdict(self)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AccessRequest:
|
class AccessRequest:
|
||||||
"""访问请求(用于需要审批的访问)"""
|
"""访问请求(用于需要审批的访问)"""
|
||||||
@@ -169,7 +161,6 @@ class AccessRequest:
|
|||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return asdict(self)
|
return asdict(self)
|
||||||
|
|
||||||
|
|
||||||
class SecurityManager:
|
class SecurityManager:
|
||||||
"""安全管理器"""
|
"""安全管理器"""
|
||||||
|
|
||||||
@@ -1194,11 +1185,9 @@ class SecurityManager:
|
|||||||
created_at=row[8],
|
created_at=row[8],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 全局安全管理器实例
|
# 全局安全管理器实例
|
||||||
_security_manager = None
|
_security_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_security_manager(db_path: str = "insightflow.db") -> SecurityManager:
|
def get_security_manager(db_path: str = "insightflow.db") -> SecurityManager:
|
||||||
"""获取安全管理器实例"""
|
"""获取安全管理器实例"""
|
||||||
global _security_manager
|
global _security_manager
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ from typing import Any
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionStatus(StrEnum):
|
class SubscriptionStatus(StrEnum):
|
||||||
"""订阅状态"""
|
"""订阅状态"""
|
||||||
|
|
||||||
@@ -32,7 +31,6 @@ class SubscriptionStatus(StrEnum):
|
|||||||
TRIAL = "trial" # 试用中
|
TRIAL = "trial" # 试用中
|
||||||
PENDING = "pending" # 待支付
|
PENDING = "pending" # 待支付
|
||||||
|
|
||||||
|
|
||||||
class PaymentProvider(StrEnum):
|
class PaymentProvider(StrEnum):
|
||||||
"""支付提供商"""
|
"""支付提供商"""
|
||||||
|
|
||||||
@@ -41,7 +39,6 @@ class PaymentProvider(StrEnum):
|
|||||||
WECHAT = "wechat" # 微信支付
|
WECHAT = "wechat" # 微信支付
|
||||||
BANK_TRANSFER = "bank_transfer" # 银行转账
|
BANK_TRANSFER = "bank_transfer" # 银行转账
|
||||||
|
|
||||||
|
|
||||||
class PaymentStatus(StrEnum):
|
class PaymentStatus(StrEnum):
|
||||||
"""支付状态"""
|
"""支付状态"""
|
||||||
|
|
||||||
@@ -52,7 +49,6 @@ class PaymentStatus(StrEnum):
|
|||||||
REFUNDED = "refunded" # 已退款
|
REFUNDED = "refunded" # 已退款
|
||||||
PARTIAL_REFUNDED = "partial_refunded" # 部分退款
|
PARTIAL_REFUNDED = "partial_refunded" # 部分退款
|
||||||
|
|
||||||
|
|
||||||
class InvoiceStatus(StrEnum):
|
class InvoiceStatus(StrEnum):
|
||||||
"""发票状态"""
|
"""发票状态"""
|
||||||
|
|
||||||
@@ -63,7 +59,6 @@ class InvoiceStatus(StrEnum):
|
|||||||
VOID = "void" # 作废
|
VOID = "void" # 作废
|
||||||
CREDIT_NOTE = "credit_note" # 贷项通知单
|
CREDIT_NOTE = "credit_note" # 贷项通知单
|
||||||
|
|
||||||
|
|
||||||
class RefundStatus(StrEnum):
|
class RefundStatus(StrEnum):
|
||||||
"""退款状态"""
|
"""退款状态"""
|
||||||
|
|
||||||
@@ -73,7 +68,6 @@ class RefundStatus(StrEnum):
|
|||||||
COMPLETED = "completed" # 已完成
|
COMPLETED = "completed" # 已完成
|
||||||
FAILED = "failed" # 失败
|
FAILED = "failed" # 失败
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SubscriptionPlan:
|
class SubscriptionPlan:
|
||||||
"""订阅计划数据类"""
|
"""订阅计划数据类"""
|
||||||
@@ -92,7 +86,6 @@ class SubscriptionPlan:
|
|||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
metadata: dict[str, Any]
|
metadata: dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Subscription:
|
class Subscription:
|
||||||
"""订阅数据类"""
|
"""订阅数据类"""
|
||||||
@@ -113,7 +106,6 @@ class Subscription:
|
|||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
metadata: dict[str, Any]
|
metadata: dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class UsageRecord:
|
class UsageRecord:
|
||||||
"""用量记录数据类"""
|
"""用量记录数据类"""
|
||||||
@@ -128,7 +120,6 @@ class UsageRecord:
|
|||||||
description: str | None
|
description: str | None
|
||||||
metadata: dict[str, Any]
|
metadata: dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Payment:
|
class Payment:
|
||||||
"""支付记录数据类"""
|
"""支付记录数据类"""
|
||||||
@@ -150,7 +141,6 @@ class Payment:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Invoice:
|
class Invoice:
|
||||||
"""发票数据类"""
|
"""发票数据类"""
|
||||||
@@ -174,7 +164,6 @@ class Invoice:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Refund:
|
class Refund:
|
||||||
"""退款数据类"""
|
"""退款数据类"""
|
||||||
@@ -197,7 +186,6 @@ class Refund:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BillingHistory:
|
class BillingHistory:
|
||||||
"""账单历史数据类"""
|
"""账单历史数据类"""
|
||||||
@@ -213,7 +201,6 @@ class BillingHistory:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
metadata: dict[str, Any]
|
metadata: dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionManager:
|
class SubscriptionManager:
|
||||||
"""订阅与计费管理器"""
|
"""订阅与计费管理器"""
|
||||||
|
|
||||||
@@ -2123,11 +2110,9 @@ class SubscriptionManager:
|
|||||||
metadata=json.loads(row["metadata"] or "{}"),
|
metadata=json.loads(row["metadata"] or "{}"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 全局订阅管理器实例
|
# 全局订阅管理器实例
|
||||||
subscription_manager = None
|
subscription_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_subscription_manager(db_path: str = "insightflow.db") -> SubscriptionManager:
|
def get_subscription_manager(db_path: str = "insightflow.db") -> SubscriptionManager:
|
||||||
"""获取订阅管理器实例(单例模式)"""
|
"""获取订阅管理器实例(单例模式)"""
|
||||||
global subscription_manager
|
global subscription_manager
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ from typing import Any
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TenantLimits:
|
class TenantLimits:
|
||||||
"""租户资源限制常量"""
|
"""租户资源限制常量"""
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ class TenantLimits:
|
|||||||
|
|
||||||
UNLIMITED = -1
|
UNLIMITED = -1
|
||||||
|
|
||||||
|
|
||||||
class TenantStatus(StrEnum):
|
class TenantStatus(StrEnum):
|
||||||
"""租户状态"""
|
"""租户状态"""
|
||||||
|
|
||||||
@@ -53,7 +51,6 @@ class TenantStatus(StrEnum):
|
|||||||
EXPIRED = "expired" # 过期
|
EXPIRED = "expired" # 过期
|
||||||
PENDING = "pending" # 待激活
|
PENDING = "pending" # 待激活
|
||||||
|
|
||||||
|
|
||||||
class TenantTier(StrEnum):
|
class TenantTier(StrEnum):
|
||||||
"""租户订阅层级"""
|
"""租户订阅层级"""
|
||||||
|
|
||||||
@@ -61,7 +58,6 @@ class TenantTier(StrEnum):
|
|||||||
PRO = "pro" # 专业版
|
PRO = "pro" # 专业版
|
||||||
ENTERPRISE = "enterprise" # 企业版
|
ENTERPRISE = "enterprise" # 企业版
|
||||||
|
|
||||||
|
|
||||||
class TenantRole(StrEnum):
|
class TenantRole(StrEnum):
|
||||||
"""租户角色"""
|
"""租户角色"""
|
||||||
|
|
||||||
@@ -70,7 +66,6 @@ class TenantRole(StrEnum):
|
|||||||
MEMBER = "member" # 成员
|
MEMBER = "member" # 成员
|
||||||
VIEWER = "viewer" # 查看者
|
VIEWER = "viewer" # 查看者
|
||||||
|
|
||||||
|
|
||||||
class DomainStatus(StrEnum):
|
class DomainStatus(StrEnum):
|
||||||
"""域名状态"""
|
"""域名状态"""
|
||||||
|
|
||||||
@@ -79,7 +74,6 @@ class DomainStatus(StrEnum):
|
|||||||
FAILED = "failed" # 验证失败
|
FAILED = "failed" # 验证失败
|
||||||
EXPIRED = "expired" # 已过期
|
EXPIRED = "expired" # 已过期
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Tenant:
|
class Tenant:
|
||||||
"""租户数据类"""
|
"""租户数据类"""
|
||||||
@@ -98,7 +92,6 @@ class Tenant:
|
|||||||
resource_limits: dict[str, Any] # 资源限制
|
resource_limits: dict[str, Any] # 资源限制
|
||||||
metadata: dict[str, Any] # 元数据
|
metadata: dict[str, Any] # 元数据
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TenantDomain:
|
class TenantDomain:
|
||||||
"""租户域名数据类"""
|
"""租户域名数据类"""
|
||||||
@@ -116,7 +109,6 @@ class TenantDomain:
|
|||||||
ssl_enabled: bool # SSL 是否启用
|
ssl_enabled: bool # SSL 是否启用
|
||||||
ssl_expires_at: datetime | None
|
ssl_expires_at: datetime | None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TenantBranding:
|
class TenantBranding:
|
||||||
"""租户品牌配置数据类"""
|
"""租户品牌配置数据类"""
|
||||||
@@ -134,7 +126,6 @@ class TenantBranding:
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TenantMember:
|
class TenantMember:
|
||||||
"""租户成员数据类"""
|
"""租户成员数据类"""
|
||||||
@@ -151,7 +142,6 @@ class TenantMember:
|
|||||||
last_active_at: datetime | None
|
last_active_at: datetime | None
|
||||||
status: str # active/pending/suspended
|
status: str # active/pending/suspended
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TenantPermission:
|
class TenantPermission:
|
||||||
"""租户权限定义数据类"""
|
"""租户权限定义数据类"""
|
||||||
@@ -166,7 +156,6 @@ class TenantPermission:
|
|||||||
conditions: dict | None # 条件限制
|
conditions: dict | None # 条件限制
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
class TenantManager:
|
class TenantManager:
|
||||||
"""租户管理器 - 多租户 SaaS 架构核心"""
|
"""租户管理器 - 多租户 SaaS 架构核心"""
|
||||||
|
|
||||||
@@ -1536,10 +1525,8 @@ class TenantManager:
|
|||||||
status=row["status"],
|
status=row["status"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# ==================== 租户上下文管理 ====================
|
# ==================== 租户上下文管理 ====================
|
||||||
|
|
||||||
|
|
||||||
class TenantContext:
|
class TenantContext:
|
||||||
"""租户上下文管理器 - 用于请求级别的租户隔离"""
|
"""租户上下文管理器 - 用于请求级别的租户隔离"""
|
||||||
|
|
||||||
@@ -1572,11 +1559,9 @@ class TenantContext:
|
|||||||
cls._current_tenant_id = None
|
cls._current_tenant_id = None
|
||||||
cls._current_user_id = None
|
cls._current_user_id = None
|
||||||
|
|
||||||
|
|
||||||
# 全局租户管理器实例
|
# 全局租户管理器实例
|
||||||
tenant_manager = None
|
tenant_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_tenant_manager(db_path: str = "insightflow.db") -> TenantManager:
|
def get_tenant_manager(db_path: str = "insightflow.db") -> TenantManager:
|
||||||
"""获取租户管理器实例(单例模式)"""
|
"""获取租户管理器实例(单例模式)"""
|
||||||
global tenant_manager
|
global tenant_manager
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ from search_manager import (
|
|||||||
# 添加 backend 到路径
|
# 添加 backend 到路径
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
def test_fulltext_search():
|
def test_fulltext_search():
|
||||||
"""测试全文搜索"""
|
"""测试全文搜索"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -66,7 +65,6 @@ def test_fulltext_search():
|
|||||||
print("\n✓ 全文搜索测试完成")
|
print("\n✓ 全文搜索测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_semantic_search():
|
def test_semantic_search():
|
||||||
"""测试语义搜索"""
|
"""测试语义搜索"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -102,7 +100,6 @@ def test_semantic_search():
|
|||||||
print("\n✓ 语义搜索测试完成")
|
print("\n✓ 语义搜索测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_entity_path_discovery():
|
def test_entity_path_discovery():
|
||||||
"""测试实体路径发现"""
|
"""测试实体路径发现"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -121,7 +118,6 @@ def test_entity_path_discovery():
|
|||||||
print("\n✓ 实体路径发现测试完成")
|
print("\n✓ 实体路径发现测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_knowledge_gap_detection():
|
def test_knowledge_gap_detection():
|
||||||
"""测试知识缺口识别"""
|
"""测试知识缺口识别"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -140,7 +136,6 @@ def test_knowledge_gap_detection():
|
|||||||
print("\n✓ 知识缺口识别测试完成")
|
print("\n✓ 知识缺口识别测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_cache_manager():
|
def test_cache_manager():
|
||||||
"""测试缓存管理器"""
|
"""测试缓存管理器"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -190,7 +185,6 @@ def test_cache_manager():
|
|||||||
print("\n✓ 缓存管理器测试完成")
|
print("\n✓ 缓存管理器测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_task_queue():
|
def test_task_queue():
|
||||||
"""测试任务队列"""
|
"""测试任务队列"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -232,7 +226,6 @@ def test_task_queue():
|
|||||||
print("\n✓ 任务队列测试完成")
|
print("\n✓ 任务队列测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_performance_monitor():
|
def test_performance_monitor():
|
||||||
"""测试性能监控"""
|
"""测试性能监控"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -277,7 +270,6 @@ def test_performance_monitor():
|
|||||||
print("\n✓ 性能监控测试完成")
|
print("\n✓ 性能监控测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_search_manager():
|
def test_search_manager():
|
||||||
"""测试搜索管理器"""
|
"""测试搜索管理器"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -298,7 +290,6 @@ def test_search_manager():
|
|||||||
print("\n✓ 搜索管理器测试完成")
|
print("\n✓ 搜索管理器测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_performance_manager():
|
def test_performance_manager():
|
||||||
"""测试性能管理器"""
|
"""测试性能管理器"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -323,7 +314,6 @@ def test_performance_manager():
|
|||||||
print("\n✓ 性能管理器测试完成")
|
print("\n✓ 性能管理器测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def run_all_tests():
|
def run_all_tests():
|
||||||
"""运行所有测试"""
|
"""运行所有测试"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -410,7 +400,6 @@ def run_all_tests():
|
|||||||
|
|
||||||
return passed == total
|
return passed == total
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
success = run_all_tests()
|
success = run_all_tests()
|
||||||
sys.exit(0 if success else 1)
|
sys.exit(0 if success else 1)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ from tenant_manager import get_tenant_manager
|
|||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
def test_tenant_management():
|
def test_tenant_management():
|
||||||
"""测试租户管理功能"""
|
"""测试租户管理功能"""
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
@@ -70,7 +69,6 @@ def test_tenant_management():
|
|||||||
|
|
||||||
return tenant.id
|
return tenant.id
|
||||||
|
|
||||||
|
|
||||||
def test_domain_management(tenant_id: str):
|
def test_domain_management(tenant_id: str):
|
||||||
"""测试域名管理功能"""
|
"""测试域名管理功能"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -120,7 +118,6 @@ def test_domain_management(tenant_id: str):
|
|||||||
|
|
||||||
return domain.id
|
return domain.id
|
||||||
|
|
||||||
|
|
||||||
def test_branding_management(tenant_id: str):
|
def test_branding_management(tenant_id: str):
|
||||||
"""测试品牌白标功能"""
|
"""测试品牌白标功能"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -160,7 +157,6 @@ def test_branding_management(tenant_id: str):
|
|||||||
|
|
||||||
return branding.id
|
return branding.id
|
||||||
|
|
||||||
|
|
||||||
def test_member_management(tenant_id: str):
|
def test_member_management(tenant_id: str):
|
||||||
"""测试成员管理功能"""
|
"""测试成员管理功能"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -221,7 +217,6 @@ def test_member_management(tenant_id: str):
|
|||||||
|
|
||||||
return member1.id, member2.id
|
return member1.id, member2.id
|
||||||
|
|
||||||
|
|
||||||
def test_usage_tracking(tenant_id: str):
|
def test_usage_tracking(tenant_id: str):
|
||||||
"""测试资源使用统计功能"""
|
"""测试资源使用统计功能"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -263,7 +258,6 @@ def test_usage_tracking(tenant_id: str):
|
|||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
def cleanup(tenant_id: str, domain_id: str, member_ids: list):
|
def cleanup(tenant_id: str, domain_id: str, member_ids: list):
|
||||||
"""清理测试数据"""
|
"""清理测试数据"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -287,7 +281,6 @@ def cleanup(tenant_id: str, domain_id: str, member_ids: list):
|
|||||||
manager.delete_tenant(tenant_id)
|
manager.delete_tenant(tenant_id)
|
||||||
print(f"✅ 租户已删除: {tenant_id}")
|
print(f"✅ 租户已删除: {tenant_id}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""主测试函数"""
|
"""主测试函数"""
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -324,6 +317,5 @@ def main():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ 清理失败: {e}")
|
print(f"⚠️ 清理失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from subscription_manager import PaymentProvider, SubscriptionManager
|
|||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
def test_subscription_manager():
|
def test_subscription_manager():
|
||||||
"""测试订阅管理器"""
|
"""测试订阅管理器"""
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
@@ -234,7 +233,6 @@ def test_subscription_manager():
|
|||||||
os.remove(db_path)
|
os.remove(db_path)
|
||||||
print(f"\n清理临时数据库: {db_path}")
|
print(f"\n清理临时数据库: {db_path}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
test_subscription_manager()
|
test_subscription_manager()
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ from ai_manager import ModelType, PredictionType, get_ai_manager
|
|||||||
# Add backend directory to path
|
# Add backend directory to path
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
def test_custom_model():
|
def test_custom_model():
|
||||||
"""测试自定义模型功能"""
|
"""测试自定义模型功能"""
|
||||||
print("\n=== 测试自定义模型 ===")
|
print("\n=== 测试自定义模型 ===")
|
||||||
@@ -92,7 +91,6 @@ def test_custom_model():
|
|||||||
|
|
||||||
return model.id
|
return model.id
|
||||||
|
|
||||||
|
|
||||||
async def test_train_and_predict(model_id: str):
|
async def test_train_and_predict(model_id: str):
|
||||||
"""测试训练和预测"""
|
"""测试训练和预测"""
|
||||||
print("\n=== 测试模型训练和预测 ===")
|
print("\n=== 测试模型训练和预测 ===")
|
||||||
@@ -119,7 +117,6 @@ async def test_train_and_predict(model_id: str):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" 预测失败: {e}")
|
print(f" 预测失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
def test_prediction_models():
|
def test_prediction_models():
|
||||||
"""测试预测模型"""
|
"""测试预测模型"""
|
||||||
print("\n=== 测试预测模型 ===")
|
print("\n=== 测试预测模型 ===")
|
||||||
@@ -167,7 +164,6 @@ def test_prediction_models():
|
|||||||
|
|
||||||
return trend_model.id, anomaly_model.id
|
return trend_model.id, anomaly_model.id
|
||||||
|
|
||||||
|
|
||||||
async def test_predictions(trend_model_id: str, anomaly_model_id: str):
|
async def test_predictions(trend_model_id: str, anomaly_model_id: str):
|
||||||
"""测试预测功能"""
|
"""测试预测功能"""
|
||||||
print("\n=== 测试预测功能 ===")
|
print("\n=== 测试预测功能 ===")
|
||||||
@@ -207,7 +203,6 @@ async def test_predictions(trend_model_id: str, anomaly_model_id: str):
|
|||||||
)
|
)
|
||||||
print(f" 检测结果: {anomaly_result.prediction_data}")
|
print(f" 检测结果: {anomaly_result.prediction_data}")
|
||||||
|
|
||||||
|
|
||||||
def test_kg_rag():
|
def test_kg_rag():
|
||||||
"""测试知识图谱 RAG"""
|
"""测试知识图谱 RAG"""
|
||||||
print("\n=== 测试知识图谱 RAG ===")
|
print("\n=== 测试知识图谱 RAG ===")
|
||||||
@@ -245,7 +240,6 @@ def test_kg_rag():
|
|||||||
|
|
||||||
return rag.id
|
return rag.id
|
||||||
|
|
||||||
|
|
||||||
async def test_kg_rag_query(rag_id: str):
|
async def test_kg_rag_query(rag_id: str):
|
||||||
"""测试 RAG 查询"""
|
"""测试 RAG 查询"""
|
||||||
print("\n=== 测试知识图谱 RAG 查询 ===")
|
print("\n=== 测试知识图谱 RAG 查询 ===")
|
||||||
@@ -306,7 +300,6 @@ async def test_kg_rag_query(rag_id: str):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" 查询失败: {e}")
|
print(f" 查询失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
async def test_smart_summary():
|
async def test_smart_summary():
|
||||||
"""测试智能摘要"""
|
"""测试智能摘要"""
|
||||||
print("\n=== 测试智能摘要 ===")
|
print("\n=== 测试智能摘要 ===")
|
||||||
@@ -354,7 +347,6 @@ async def test_smart_summary():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" 生成失败: {e}")
|
print(f" 生成失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""主测试函数"""
|
"""主测试函数"""
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
@@ -392,6 +384,5 @@ async def main():
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ backend_dir = os.path.dirname(os.path.abspath(__file__))
|
|||||||
if backend_dir not in sys.path:
|
if backend_dir not in sys.path:
|
||||||
sys.path.insert(0, backend_dir)
|
sys.path.insert(0, backend_dir)
|
||||||
|
|
||||||
|
|
||||||
class TestGrowthManager:
|
class TestGrowthManager:
|
||||||
"""测试 Growth Manager 功能"""
|
"""测试 Growth Manager 功能"""
|
||||||
|
|
||||||
@@ -735,12 +734,10 @@ class TestGrowthManager:
|
|||||||
print("✨ 测试完成!")
|
print("✨ 测试完成!")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
tester = TestGrowthManager()
|
tester = TestGrowthManager()
|
||||||
await tester.run_all_tests()
|
await tester.run_all_tests()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ backend_dir = os.path.dirname(os.path.abspath(__file__))
|
|||||||
if backend_dir not in sys.path:
|
if backend_dir not in sys.path:
|
||||||
sys.path.insert(0, backend_dir)
|
sys.path.insert(0, backend_dir)
|
||||||
|
|
||||||
|
|
||||||
class TestDeveloperEcosystem:
|
class TestDeveloperEcosystem:
|
||||||
"""开发者生态系统测试类"""
|
"""开发者生态系统测试类"""
|
||||||
|
|
||||||
@@ -687,12 +686,10 @@ console.log('Upload complete:', result.id);
|
|||||||
|
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
test = TestDeveloperEcosystem()
|
test = TestDeveloperEcosystem()
|
||||||
test.run_all_tests()
|
test.run_all_tests()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ backend_dir = os.path.dirname(os.path.abspath(__file__))
|
|||||||
if backend_dir not in sys.path:
|
if backend_dir not in sys.path:
|
||||||
sys.path.insert(0, backend_dir)
|
sys.path.insert(0, backend_dir)
|
||||||
|
|
||||||
|
|
||||||
class TestOpsManager:
|
class TestOpsManager:
|
||||||
"""测试运维与监控管理器"""
|
"""测试运维与监控管理器"""
|
||||||
|
|
||||||
@@ -701,12 +700,10 @@ class TestOpsManager:
|
|||||||
|
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
test = TestOpsManager()
|
test = TestOpsManager()
|
||||||
test.run_all_tests()
|
test.run_all_tests()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import time
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class TingwuClient:
|
class TingwuClient:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.access_key = os.getenv("ALI_ACCESS_KEY", "")
|
self.access_key = os.getenv("ALI_ACCESS_KEY", "")
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ from apscheduler.triggers.interval import IntervalTrigger
|
|||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class WorkflowStatus(Enum):
|
class WorkflowStatus(Enum):
|
||||||
"""工作流状态"""
|
"""工作流状态"""
|
||||||
|
|
||||||
@@ -42,7 +41,6 @@ class WorkflowStatus(Enum):
|
|||||||
ERROR = "error"
|
ERROR = "error"
|
||||||
COMPLETED = "completed"
|
COMPLETED = "completed"
|
||||||
|
|
||||||
|
|
||||||
class WorkflowType(Enum):
|
class WorkflowType(Enum):
|
||||||
"""工作流类型"""
|
"""工作流类型"""
|
||||||
|
|
||||||
@@ -52,7 +50,6 @@ class WorkflowType(Enum):
|
|||||||
SCHEDULED_REPORT = "scheduled_report" # 定时报告
|
SCHEDULED_REPORT = "scheduled_report" # 定时报告
|
||||||
CUSTOM = "custom" # 自定义工作流
|
CUSTOM = "custom" # 自定义工作流
|
||||||
|
|
||||||
|
|
||||||
class WebhookType(Enum):
|
class WebhookType(Enum):
|
||||||
"""Webhook 类型"""
|
"""Webhook 类型"""
|
||||||
|
|
||||||
@@ -61,7 +58,6 @@ class WebhookType(Enum):
|
|||||||
SLACK = "slack"
|
SLACK = "slack"
|
||||||
CUSTOM = "custom"
|
CUSTOM = "custom"
|
||||||
|
|
||||||
|
|
||||||
class TaskStatus(Enum):
|
class TaskStatus(Enum):
|
||||||
"""任务执行状态"""
|
"""任务执行状态"""
|
||||||
|
|
||||||
@@ -71,7 +67,6 @@ class TaskStatus(Enum):
|
|||||||
FAILED = "failed"
|
FAILED = "failed"
|
||||||
CANCELLED = "cancelled"
|
CANCELLED = "cancelled"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WorkflowTask:
|
class WorkflowTask:
|
||||||
"""工作流任务定义"""
|
"""工作流任务定义"""
|
||||||
@@ -95,7 +90,6 @@ class WorkflowTask:
|
|||||||
if not self.updated_at:
|
if not self.updated_at:
|
||||||
self.updated_at = self.created_at
|
self.updated_at = self.created_at
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WebhookConfig:
|
class WebhookConfig:
|
||||||
"""Webhook 配置"""
|
"""Webhook 配置"""
|
||||||
@@ -120,7 +114,6 @@ class WebhookConfig:
|
|||||||
if not self.updated_at:
|
if not self.updated_at:
|
||||||
self.updated_at = self.created_at
|
self.updated_at = self.created_at
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Workflow:
|
class Workflow:
|
||||||
"""工作流定义"""
|
"""工作流定义"""
|
||||||
@@ -150,7 +143,6 @@ class Workflow:
|
|||||||
if not self.updated_at:
|
if not self.updated_at:
|
||||||
self.updated_at = self.created_at
|
self.updated_at = self.created_at
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WorkflowLog:
|
class WorkflowLog:
|
||||||
"""工作流执行日志"""
|
"""工作流执行日志"""
|
||||||
@@ -171,7 +163,6 @@ class WorkflowLog:
|
|||||||
if not self.created_at:
|
if not self.created_at:
|
||||||
self.created_at = datetime.now().isoformat()
|
self.created_at = datetime.now().isoformat()
|
||||||
|
|
||||||
|
|
||||||
class WebhookNotifier:
|
class WebhookNotifier:
|
||||||
"""Webhook 通知器 - 支持飞书、钉钉、Slack"""
|
"""Webhook 通知器 - 支持飞书、钉钉、Slack"""
|
||||||
|
|
||||||
@@ -313,7 +304,6 @@ class WebhookNotifier:
|
|||||||
"""关闭 HTTP 客户端"""
|
"""关闭 HTTP 客户端"""
|
||||||
await self.http_client.aclose()
|
await self.http_client.aclose()
|
||||||
|
|
||||||
|
|
||||||
class WorkflowManager:
|
class WorkflowManager:
|
||||||
"""工作流管理器 - 核心管理类"""
|
"""工作流管理器 - 核心管理类"""
|
||||||
|
|
||||||
@@ -1437,11 +1427,9 @@ class WorkflowManager:
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Singleton instance
|
# Singleton instance
|
||||||
_workflow_manager = None
|
_workflow_manager = None
|
||||||
|
|
||||||
|
|
||||||
def get_workflow_manager(db_manager=None) -> WorkflowManager:
|
def get_workflow_manager(db_manager=None) -> WorkflowManager:
|
||||||
"""获取 WorkflowManager 单例"""
|
"""获取 WorkflowManager 单例"""
|
||||||
global _workflow_manager
|
global _workflow_manager
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ InsightFlow 代码审查与自动修复脚本
|
|||||||
import ast
|
import ast
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
|
|
||||||
class CodeIssue:
|
class CodeIssue:
|
||||||
|
|||||||
Reference in New Issue
Block a user