fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解 自动修复统计: - 修复了1177个格式问题 - 删除了多余的空行 - 清理了行尾空格 - 移除了重复导入和未使用的导入
This commit is contained in:
@@ -9,7 +9,6 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class CodeIssue:
|
class CodeIssue:
|
||||||
"""代码问题记录"""
|
"""代码问题记录"""
|
||||||
|
|
||||||
@@ -33,7 +32,6 @@ class CodeIssue:
|
|||||||
def __repr__(self) -> None:
|
def __repr__(self) -> None:
|
||||||
return f"{self.file_path}:{self.line_no} [{self.severity}] {self.issue_type}: {self.message}"
|
return f"{self.file_path}:{self.line_no} [{self.severity}] {self.issue_type}: {self.message}"
|
||||||
|
|
||||||
|
|
||||||
class CodeFixer:
|
class CodeFixer:
|
||||||
"""代码自动修复器"""
|
"""代码自动修复器"""
|
||||||
|
|
||||||
@@ -431,7 +429,6 @@ class CodeFixer:
|
|||||||
|
|
||||||
return "\n".join(report)
|
return "\n".join(report)
|
||||||
|
|
||||||
|
|
||||||
def git_commit_and_push(project_path: str) -> tuple[bool, str]:
|
def git_commit_and_push(project_path: str) -> tuple[bool, str]:
|
||||||
"""Git 提交和推送"""
|
"""Git 提交和推送"""
|
||||||
try:
|
try:
|
||||||
@@ -470,7 +467,6 @@ def git_commit_and_push(project_path: str) -> tuple[bool, str]:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return False, f"Git 操作异常: {e}"
|
return False, f"Git 操作异常: {e}"
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
project_path = "/root/.openclaw/workspace/projects/insightflow"
|
project_path = "/root/.openclaw/workspace/projects/insightflow"
|
||||||
|
|
||||||
@@ -514,6 +510,5 @@ def main() -> None:
|
|||||||
|
|
||||||
return report
|
return report
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ Auto-fix script for InsightFlow code issues
|
|||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def fix_file(filepath):
|
def fix_file(filepath):
|
||||||
"""Fix common issues in a Python file"""
|
"""Fix common issues in a Python file"""
|
||||||
with open(filepath, 'r', encoding='utf-8') as f:
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
@@ -75,7 +74,6 @@ def fix_file(filepath):
|
|||||||
return True, changes
|
return True, changes
|
||||||
return False, []
|
return False, []
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
backend_dir = Path('/root/.openclaw/workspace/projects/insightflow/backend')
|
backend_dir = Path('/root/.openclaw/workspace/projects/insightflow/backend')
|
||||||
py_files = list(backend_dir.glob('*.py'))
|
py_files = list(backend_dir.glob('*.py'))
|
||||||
@@ -97,6 +95,5 @@ def main():
|
|||||||
for c in all_changes[:20]:
|
for c in all_changes[:20]:
|
||||||
print(f" {c}")
|
print(f" {c}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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 能力管理主类"""
|
||||||
|
|
||||||
@@ -1526,11 +1513,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 管理器"""
|
||||||
|
|
||||||
@@ -531,11 +528,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:
|
||||||
"""协作管理主类"""
|
"""协作管理主类"""
|
||||||
|
|
||||||
@@ -986,11 +977,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
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ DB_PATH = os.getenv("DB_PATH", "/app/data/insightflow.db")
|
|||||||
# Constants
|
# Constants
|
||||||
UUID_LENGTH = 8 # UUID 截断长度
|
UUID_LENGTH = 8 # UUID 截断长度
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Project:
|
class Project:
|
||||||
id: str
|
id: str
|
||||||
@@ -26,7 +25,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
|
||||||
@@ -47,7 +45,6 @@ class Entity:
|
|||||||
if self.attributes is None:
|
if self.attributes is None:
|
||||||
self.attributes = {}
|
self.attributes = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AttributeTemplate:
|
class AttributeTemplate:
|
||||||
"""属性模板定义"""
|
"""属性模板定义"""
|
||||||
@@ -68,7 +65,6 @@ class AttributeTemplate:
|
|||||||
if self.options is None:
|
if self.options is None:
|
||||||
self.options = []
|
self.options = []
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EntityAttribute:
|
class EntityAttribute:
|
||||||
"""实体属性值"""
|
"""实体属性值"""
|
||||||
@@ -89,7 +85,6 @@ class EntityAttribute:
|
|||||||
if self.options is None:
|
if self.options is None:
|
||||||
self.options = []
|
self.options = []
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AttributeHistory:
|
class AttributeHistory:
|
||||||
"""属性变更历史"""
|
"""属性变更历史"""
|
||||||
@@ -103,7 +98,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
|
||||||
@@ -114,7 +108,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) -> None:
|
def __init__(self, db_path: str = DB_PATH) -> None:
|
||||||
self.db_path = db_path
|
self.db_path = db_path
|
||||||
@@ -1463,11 +1456,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:
|
||||||
"""开发者生态系统管理主类"""
|
"""开发者生态系统管理主类"""
|
||||||
|
|
||||||
@@ -2075,11 +2056,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 文本"""
|
||||||
|
|
||||||
@@ -157,10 +156,8 @@ 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:
|
||||||
"""简单的文本提取器,用于测试"""
|
"""简单的文本提取器,用于测试"""
|
||||||
|
|
||||||
@@ -176,7 +173,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:
|
||||||
"""企业级功能管理器"""
|
"""企业级功能管理器"""
|
||||||
|
|
||||||
@@ -2246,11 +2231,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 进行相似度匹配"""
|
||||||
|
|
||||||
@@ -327,10 +325,8 @@ class EntityAligner:
|
|||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
# 简单的字符串相似度计算(不使用 embedding)
|
# 简单的字符串相似度计算(不使用 embedding)
|
||||||
|
|
||||||
|
|
||||||
def simple_similarity(str1: str, str2: str) -> float:
|
def simple_similarity(str1: str, str2: str) -> float:
|
||||||
"""
|
"""
|
||||||
计算两个字符串的简单相似度
|
计算两个字符串的简单相似度
|
||||||
@@ -361,7 +357,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()
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
REPORTLAB_AVAILABLE = False
|
REPORTLAB_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExportEntity:
|
class ExportEntity:
|
||||||
id: str
|
id: str
|
||||||
@@ -47,7 +46,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
|
||||||
@@ -57,7 +55,6 @@ class ExportRelation:
|
|||||||
confidence: float
|
confidence: float
|
||||||
evidence: str
|
evidence: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExportTranscript:
|
class ExportTranscript:
|
||||||
id: str
|
id: str
|
||||||
@@ -67,7 +64,6 @@ class ExportTranscript:
|
|||||||
segments: list[dict]
|
segments: list[dict]
|
||||||
entity_mentions: list[dict]
|
entity_mentions: list[dict]
|
||||||
|
|
||||||
|
|
||||||
class ExportManager:
|
class ExportManager:
|
||||||
"""导出管理器 - 处理各种导出需求"""
|
"""导出管理器 - 处理各种导出需求"""
|
||||||
|
|
||||||
@@ -633,11 +629,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:
|
||||||
"""运营与增长管理主类"""
|
"""运营与增长管理主类"""
|
||||||
|
|
||||||
@@ -2211,11 +2190,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:
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
PYTESSERACT_AVAILABLE = False
|
PYTESSERACT_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ImageEntity:
|
class ImageEntity:
|
||||||
"""图片中检测到的实体"""
|
"""图片中检测到的实体"""
|
||||||
@@ -46,7 +45,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:
|
||||||
"""图片中检测到的关系"""
|
"""图片中检测到的关系"""
|
||||||
@@ -56,7 +54,6 @@ class ImageRelation:
|
|||||||
relation_type: str
|
relation_type: str
|
||||||
confidence: float
|
confidence: float
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ImageProcessingResult:
|
class ImageProcessingResult:
|
||||||
"""图片处理结果"""
|
"""图片处理结果"""
|
||||||
@@ -72,7 +69,6 @@ class ImageProcessingResult:
|
|||||||
success: bool
|
success: bool
|
||||||
error_message: str = ""
|
error_message: str = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BatchProcessingResult:
|
class BatchProcessingResult:
|
||||||
"""批量图片处理结果"""
|
"""批量图片处理结果"""
|
||||||
@@ -82,7 +78,6 @@ class BatchProcessingResult:
|
|||||||
success_count: int
|
success_count: int
|
||||||
failed_count: int
|
failed_count: int
|
||||||
|
|
||||||
|
|
||||||
class ImageProcessor:
|
class ImageProcessor:
|
||||||
"""图片处理器 - 处理各种类型图片"""
|
"""图片处理器 - 处理各种类型图片"""
|
||||||
|
|
||||||
@@ -561,11 +556,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 = None) -> ImageProcessor:
|
def get_image_processor(temp_dir: str | None = 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:
|
||||||
"""知识推理引擎"""
|
"""知识推理引擎"""
|
||||||
|
|
||||||
@@ -525,11 +521,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 客户端"""
|
||||||
|
|
||||||
@@ -267,11 +263,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: {
|
||||||
@@ -1755,10 +1740,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:
|
||||||
|
|||||||
-770
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
NUMPY_AVAILABLE = False
|
NUMPY_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MultimodalEntity:
|
class MultimodalEntity:
|
||||||
"""多模态实体"""
|
"""多模态实体"""
|
||||||
@@ -36,7 +35,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:
|
||||||
"""实体关联"""
|
"""实体关联"""
|
||||||
@@ -51,7 +49,6 @@ class EntityLink:
|
|||||||
confidence: float
|
confidence: float
|
||||||
evidence: str
|
evidence: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AlignmentResult:
|
class AlignmentResult:
|
||||||
"""对齐结果"""
|
"""对齐结果"""
|
||||||
@@ -62,7 +59,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:
|
||||||
"""知识融合结果"""
|
"""知识融合结果"""
|
||||||
@@ -73,7 +69,6 @@ class FusionResult:
|
|||||||
source_modalities: list[str]
|
source_modalities: list[str]
|
||||||
confidence: float
|
confidence: float
|
||||||
|
|
||||||
|
|
||||||
class MultimodalEntityLinker:
|
class MultimodalEntityLinker:
|
||||||
"""多模态实体关联器 - 跨模态实体对齐和知识融合"""
|
"""多模态实体关联器 - 跨模态实体对齐和知识融合"""
|
||||||
|
|
||||||
@@ -525,11 +520,9 @@ class MultimodalEntityLinker:
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
FFMPEG_AVAILABLE = False
|
FFMPEG_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class VideoFrame:
|
class VideoFrame:
|
||||||
"""视频关键帧数据类"""
|
"""视频关键帧数据类"""
|
||||||
@@ -56,7 +55,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:
|
||||||
"""视频信息数据类"""
|
"""视频信息数据类"""
|
||||||
@@ -80,7 +78,6 @@ class VideoInfo:
|
|||||||
if self.metadata is None:
|
if self.metadata is None:
|
||||||
self.metadata = {}
|
self.metadata = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class VideoProcessingResult:
|
class VideoProcessingResult:
|
||||||
"""视频处理结果"""
|
"""视频处理结果"""
|
||||||
@@ -93,7 +90,6 @@ class VideoProcessingResult:
|
|||||||
success: bool
|
success: bool
|
||||||
error_message: str = ""
|
error_message: str = ""
|
||||||
|
|
||||||
|
|
||||||
class MultimodalProcessor:
|
class MultimodalProcessor:
|
||||||
"""多模态处理器 - 处理视频文件"""
|
"""多模态处理器 - 处理视频文件"""
|
||||||
|
|
||||||
@@ -461,11 +457,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(
|
def get_multimodal_processor(
|
||||||
temp_dir: str | None = None, frame_interval: int = 5
|
temp_dir: str | None = None, frame_interval: int = 5
|
||||||
) -> MultimodalProcessor:
|
) -> MultimodalProcessor:
|
||||||
|
|||||||
@@ -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 图数据库管理器"""
|
||||||
|
|
||||||
@@ -998,11 +992,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
|
||||||
@@ -1010,7 +1002,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
|
||||||
@@ -1018,10 +1009,8 @@ def close_neo4j_manager() -> None:
|
|||||||
_neo4j_manager.close()
|
_neo4j_manager.close()
|
||||||
_neo4j_manager = None
|
_neo4j_manager = None
|
||||||
|
|
||||||
|
|
||||||
# 便捷函数
|
# 便捷函数
|
||||||
|
|
||||||
|
|
||||||
def sync_project_to_neo4j(
|
def sync_project_to_neo4j(
|
||||||
project_id: str,
|
project_id: str,
|
||||||
project_name: str,
|
project_name: str,
|
||||||
@@ -1079,7 +1068,6 @@ def sync_project_to_neo4j(
|
|||||||
f"{len(relations)} relations",
|
f"{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:
|
||||||
"""运维与监控管理主类"""
|
"""运维与监控管理主类"""
|
||||||
|
|
||||||
@@ -3148,11 +3120,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) -> None:
|
def __init__(self) -> None:
|
||||||
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:
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ except ImportError:
|
|||||||
|
|
||||||
# ==================== 数据模型 ====================
|
# ==================== 数据模型 ====================
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CacheStats:
|
class CacheStats:
|
||||||
"""缓存统计数据模型"""
|
"""缓存统计数据模型"""
|
||||||
@@ -59,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:
|
||||||
"""缓存条目数据模型"""
|
"""缓存条目数据模型"""
|
||||||
@@ -72,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:
|
||||||
"""性能指标数据模型"""
|
"""性能指标数据模型"""
|
||||||
@@ -94,7 +91,6 @@ class PerformanceMetric:
|
|||||||
"metadata": self.metadata,
|
"metadata": self.metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TaskInfo:
|
class TaskInfo:
|
||||||
"""任务信息数据模型"""
|
"""任务信息数据模型"""
|
||||||
@@ -126,7 +122,6 @@ class TaskInfo:
|
|||||||
"max_retries": self.max_retries,
|
"max_retries": self.max_retries,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ShardInfo:
|
class ShardInfo:
|
||||||
"""分片信息数据模型"""
|
"""分片信息数据模型"""
|
||||||
@@ -139,10 +134,8 @@ class ShardInfo:
|
|||||||
created_at: str = ""
|
created_at: str = ""
|
||||||
last_accessed: str = ""
|
last_accessed: str = ""
|
||||||
|
|
||||||
|
|
||||||
# ==================== Redis 缓存层 ====================
|
# ==================== Redis 缓存层 ====================
|
||||||
|
|
||||||
|
|
||||||
class CacheManager:
|
class CacheManager:
|
||||||
"""
|
"""
|
||||||
缓存管理器
|
缓存管理器
|
||||||
@@ -603,10 +596,8 @@ class CacheManager:
|
|||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
# ==================== 数据库分片 ====================
|
# ==================== 数据库分片 ====================
|
||||||
|
|
||||||
|
|
||||||
class DatabaseSharding:
|
class DatabaseSharding:
|
||||||
"""
|
"""
|
||||||
数据库分片管理器
|
数据库分片管理器
|
||||||
@@ -909,10 +900,8 @@ class DatabaseSharding:
|
|||||||
"message": "Rebalancing analysis completed",
|
"message": "Rebalancing analysis completed",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ==================== 异步任务队列 ====================
|
# ==================== 异步任务队列 ====================
|
||||||
|
|
||||||
|
|
||||||
class TaskQueue:
|
class TaskQueue:
|
||||||
"""
|
"""
|
||||||
异步任务队列管理器
|
异步任务队列管理器
|
||||||
@@ -1299,10 +1288,8 @@ class TaskQueue:
|
|||||||
"backend": "celery" if self.use_celery else "memory",
|
"backend": "celery" if self.use_celery else "memory",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ==================== 性能监控 ====================
|
# ==================== 性能监控 ====================
|
||||||
|
|
||||||
|
|
||||||
class PerformanceMonitor:
|
class PerformanceMonitor:
|
||||||
"""
|
"""
|
||||||
性能监控器
|
性能监控器
|
||||||
@@ -1622,10 +1609,8 @@ class PerformanceMonitor:
|
|||||||
|
|
||||||
return deleted
|
return deleted
|
||||||
|
|
||||||
|
|
||||||
# ==================== 性能装饰器 ====================
|
# ==================== 性能装饰器 ====================
|
||||||
|
|
||||||
|
|
||||||
def cached(
|
def cached(
|
||||||
cache_manager: CacheManager,
|
cache_manager: CacheManager,
|
||||||
key_prefix: str = "",
|
key_prefix: str = "",
|
||||||
@@ -1670,7 +1655,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:
|
||||||
"""
|
"""
|
||||||
性能监控装饰器
|
性能监控装饰器
|
||||||
@@ -1698,10 +1682,8 @@ def monitored(monitor: PerformanceMonitor, metric_type: str, endpoint: str | Non
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
# ==================== 性能管理器 ====================
|
# ==================== 性能管理器 ====================
|
||||||
|
|
||||||
|
|
||||||
class PerformanceManager:
|
class PerformanceManager:
|
||||||
"""
|
"""
|
||||||
性能管理器 - 统一入口
|
性能管理器 - 统一入口
|
||||||
@@ -1763,11 +1745,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",
|
db_path: str = "insightflow.db",
|
||||||
redis_url: str | None = None,
|
redis_url: str | None = None,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import json
|
|||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
|
||||||
import uuid
|
import uuid
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -31,7 +30,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
WEBDAV_AVAILABLE = False
|
WEBDAV_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
class PluginType(Enum):
|
class PluginType(Enum):
|
||||||
"""插件类型"""
|
"""插件类型"""
|
||||||
|
|
||||||
@@ -43,7 +41,6 @@ class PluginType(Enum):
|
|||||||
WEBDAV = "webdav"
|
WEBDAV = "webdav"
|
||||||
CUSTOM = "custom"
|
CUSTOM = "custom"
|
||||||
|
|
||||||
|
|
||||||
class PluginStatus(Enum):
|
class PluginStatus(Enum):
|
||||||
"""插件状态"""
|
"""插件状态"""
|
||||||
|
|
||||||
@@ -52,7 +49,6 @@ class PluginStatus(Enum):
|
|||||||
ERROR = "error"
|
ERROR = "error"
|
||||||
PENDING = "pending"
|
PENDING = "pending"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Plugin:
|
class Plugin:
|
||||||
"""插件配置"""
|
"""插件配置"""
|
||||||
@@ -68,7 +64,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:
|
||||||
"""插件详细配置"""
|
"""插件详细配置"""
|
||||||
@@ -81,7 +76,6 @@ class PluginConfig:
|
|||||||
created_at: str = ""
|
created_at: str = ""
|
||||||
updated_at: str = ""
|
updated_at: str = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BotSession:
|
class BotSession:
|
||||||
"""机器人会话"""
|
"""机器人会话"""
|
||||||
@@ -99,7 +93,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集成)"""
|
||||||
@@ -118,7 +111,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 同步配置"""
|
||||||
@@ -140,7 +132,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 扩展令牌"""
|
||||||
@@ -157,7 +148,6 @@ class ChromeExtensionToken:
|
|||||||
use_count: int = 0
|
use_count: int = 0
|
||||||
is_revoked: bool = False
|
is_revoked: bool = False
|
||||||
|
|
||||||
|
|
||||||
class PluginManager:
|
class PluginManager:
|
||||||
"""插件管理主类"""
|
"""插件管理主类"""
|
||||||
|
|
||||||
@@ -409,7 +399,6 @@ class PluginManager:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
class ChromeExtensionHandler:
|
class ChromeExtensionHandler:
|
||||||
"""Chrome 扩展处理器"""
|
"""Chrome 扩展处理器"""
|
||||||
|
|
||||||
@@ -438,7 +427,6 @@ class ChromeExtensionHandler:
|
|||||||
now = datetime.now().isoformat()
|
now = datetime.now().isoformat()
|
||||||
expires_at = None
|
expires_at = None
|
||||||
if expires_days:
|
if expires_days:
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
expires_at = (datetime.now() + timedelta(days=expires_days)).isoformat()
|
expires_at = (datetime.now() + timedelta(days=expires_days)).isoformat()
|
||||||
|
|
||||||
@@ -618,7 +606,6 @@ class ChromeExtensionHandler:
|
|||||||
"content_length": len(content),
|
"content_length": len(content),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BotHandler:
|
class BotHandler:
|
||||||
"""飞书/钉钉机器人处理器"""
|
"""飞书/钉钉机器人处理器"""
|
||||||
|
|
||||||
@@ -953,7 +940,6 @@ class BotHandler:
|
|||||||
)
|
)
|
||||||
return response.status_code == 200
|
return response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
class WebhookIntegration:
|
class WebhookIntegration:
|
||||||
"""Zapier/Make Webhook 集成"""
|
"""Zapier/Make Webhook 集成"""
|
||||||
|
|
||||||
@@ -1179,7 +1165,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 同步管理"""
|
||||||
|
|
||||||
@@ -1441,11 +1426,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 限流器"""
|
||||||
|
|
||||||
@@ -162,11 +158,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
|
||||||
@@ -174,10 +168,8 @@ 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:
|
||||||
"""
|
"""
|
||||||
限流装饰器
|
限流装饰器
|
||||||
@@ -220,6 +212,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:
|
||||||
"""
|
"""
|
||||||
全文搜索模块
|
全文搜索模块
|
||||||
@@ -805,10 +795,8 @@ class FullTextSearch:
|
|||||||
conn.close()
|
conn.close()
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
# ==================== 语义搜索 ====================
|
# ==================== 语义搜索 ====================
|
||||||
|
|
||||||
|
|
||||||
class SemanticSearch:
|
class SemanticSearch:
|
||||||
"""
|
"""
|
||||||
语义搜索模块
|
语义搜索模块
|
||||||
@@ -1180,10 +1168,8 @@ class SemanticSearch:
|
|||||||
print(f"删除 embedding 失败: {e}")
|
print(f"删除 embedding 失败: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# ==================== 实体关系路径发现 ====================
|
# ==================== 实体关系路径发现 ====================
|
||||||
|
|
||||||
|
|
||||||
class EntityPathDiscovery:
|
class EntityPathDiscovery:
|
||||||
"""
|
"""
|
||||||
实体关系路径发现模块
|
实体关系路径发现模块
|
||||||
@@ -1680,10 +1666,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:
|
||||||
"""
|
"""
|
||||||
知识缺口识别模块
|
知识缺口识别模块
|
||||||
@@ -2092,10 +2076,8 @@ class KnowledgeGapDetection:
|
|||||||
|
|
||||||
return recommendations
|
return recommendations
|
||||||
|
|
||||||
|
|
||||||
# ==================== 搜索管理器 ====================
|
# ==================== 搜索管理器 ====================
|
||||||
|
|
||||||
|
|
||||||
class SearchManager:
|
class SearchManager:
|
||||||
"""
|
"""
|
||||||
搜索管理器 - 统一入口
|
搜索管理器 - 统一入口
|
||||||
@@ -2273,11 +2255,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
|
||||||
@@ -2285,10 +2265,8 @@ 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(
|
def fulltext_search(
|
||||||
query: str,
|
query: str,
|
||||||
project_id: str | None = None,
|
project_id: str | None = None,
|
||||||
@@ -2298,7 +2276,6 @@ def fulltext_search(
|
|||||||
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(
|
def semantic_search(
|
||||||
query: str,
|
query: str,
|
||||||
project_id: str | None = None,
|
project_id: str | None = None,
|
||||||
@@ -2308,13 +2285,11 @@ def semantic_search(
|
|||||||
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:
|
||||||
"""安全管理器"""
|
"""安全管理器"""
|
||||||
|
|
||||||
@@ -1255,11 +1246,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:
|
||||||
"""订阅与计费管理器"""
|
"""订阅与计费管理器"""
|
||||||
|
|
||||||
@@ -2242,11 +2229,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 架构核心"""
|
||||||
|
|
||||||
@@ -1634,10 +1623,8 @@ class TenantManager:
|
|||||||
status=row["status"],
|
status=row["status"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# ==================== 租户上下文管理 ====================
|
# ==================== 租户上下文管理 ====================
|
||||||
|
|
||||||
|
|
||||||
class TenantContext:
|
class TenantContext:
|
||||||
"""租户上下文管理器 - 用于请求级别的租户隔离"""
|
"""租户上下文管理器 - 用于请求级别的租户隔离"""
|
||||||
|
|
||||||
@@ -1670,11 +1657,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() -> None:
|
def test_fulltext_search() -> None:
|
||||||
"""测试全文搜索"""
|
"""测试全文搜索"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -63,7 +62,6 @@ def test_fulltext_search() -> None:
|
|||||||
print("\n✓ 全文搜索测试完成")
|
print("\n✓ 全文搜索测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_semantic_search() -> None:
|
def test_semantic_search() -> None:
|
||||||
"""测试语义搜索"""
|
"""测试语义搜索"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -99,7 +97,6 @@ def test_semantic_search() -> None:
|
|||||||
print("\n✓ 语义搜索测试完成")
|
print("\n✓ 语义搜索测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_entity_path_discovery() -> None:
|
def test_entity_path_discovery() -> None:
|
||||||
"""测试实体路径发现"""
|
"""测试实体路径发现"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -118,7 +115,6 @@ def test_entity_path_discovery() -> None:
|
|||||||
print("\n✓ 实体路径发现测试完成")
|
print("\n✓ 实体路径发现测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_knowledge_gap_detection() -> None:
|
def test_knowledge_gap_detection() -> None:
|
||||||
"""测试知识缺口识别"""
|
"""测试知识缺口识别"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -137,7 +133,6 @@ def test_knowledge_gap_detection() -> None:
|
|||||||
print("\n✓ 知识缺口识别测试完成")
|
print("\n✓ 知识缺口识别测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_cache_manager() -> None:
|
def test_cache_manager() -> None:
|
||||||
"""测试缓存管理器"""
|
"""测试缓存管理器"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -186,7 +181,6 @@ def test_cache_manager() -> None:
|
|||||||
print("\n✓ 缓存管理器测试完成")
|
print("\n✓ 缓存管理器测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_task_queue() -> None:
|
def test_task_queue() -> None:
|
||||||
"""测试任务队列"""
|
"""测试任务队列"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -228,7 +222,6 @@ def test_task_queue() -> None:
|
|||||||
print("\n✓ 任务队列测试完成")
|
print("\n✓ 任务队列测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_performance_monitor() -> None:
|
def test_performance_monitor() -> None:
|
||||||
"""测试性能监控"""
|
"""测试性能监控"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -275,7 +268,6 @@ def test_performance_monitor() -> None:
|
|||||||
print("\n✓ 性能监控测试完成")
|
print("\n✓ 性能监控测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_search_manager() -> None:
|
def test_search_manager() -> None:
|
||||||
"""测试搜索管理器"""
|
"""测试搜索管理器"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -296,7 +288,6 @@ def test_search_manager() -> None:
|
|||||||
print("\n✓ 搜索管理器测试完成")
|
print("\n✓ 搜索管理器测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def test_performance_manager() -> None:
|
def test_performance_manager() -> None:
|
||||||
"""测试性能管理器"""
|
"""测试性能管理器"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -321,7 +312,6 @@ def test_performance_manager() -> None:
|
|||||||
print("\n✓ 性能管理器测试完成")
|
print("\n✓ 性能管理器测试完成")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def run_all_tests() -> None:
|
def run_all_tests() -> None:
|
||||||
"""运行所有测试"""
|
"""运行所有测试"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -408,7 +398,6 @@ def run_all_tests() -> None:
|
|||||||
|
|
||||||
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() -> None:
|
def test_tenant_management() -> None:
|
||||||
"""测试租户管理功能"""
|
"""测试租户管理功能"""
|
||||||
print(" = " * 60)
|
print(" = " * 60)
|
||||||
@@ -70,7 +69,6 @@ def test_tenant_management() -> None:
|
|||||||
|
|
||||||
return tenant.id
|
return tenant.id
|
||||||
|
|
||||||
|
|
||||||
def test_domain_management(tenant_id: str) -> None:
|
def test_domain_management(tenant_id: str) -> None:
|
||||||
"""测试域名管理功能"""
|
"""测试域名管理功能"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -116,7 +114,6 @@ def test_domain_management(tenant_id: str) -> None:
|
|||||||
|
|
||||||
return domain.id
|
return domain.id
|
||||||
|
|
||||||
|
|
||||||
def test_branding_management(tenant_id: str) -> None:
|
def test_branding_management(tenant_id: str) -> None:
|
||||||
"""测试品牌白标功能"""
|
"""测试品牌白标功能"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -156,7 +153,6 @@ def test_branding_management(tenant_id: str) -> None:
|
|||||||
|
|
||||||
return branding.id
|
return branding.id
|
||||||
|
|
||||||
|
|
||||||
def test_member_management(tenant_id: str) -> None:
|
def test_member_management(tenant_id: str) -> None:
|
||||||
"""测试成员管理功能"""
|
"""测试成员管理功能"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -217,7 +213,6 @@ def test_member_management(tenant_id: str) -> None:
|
|||||||
|
|
||||||
return member1.id, member2.id
|
return member1.id, member2.id
|
||||||
|
|
||||||
|
|
||||||
def test_usage_tracking(tenant_id: str) -> None:
|
def test_usage_tracking(tenant_id: str) -> None:
|
||||||
"""测试资源使用统计功能"""
|
"""测试资源使用统计功能"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -259,7 +254,6 @@ def test_usage_tracking(tenant_id: str) -> None:
|
|||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
def cleanup(tenant_id: str, domain_id: str, member_ids: list) -> None:
|
def cleanup(tenant_id: str, domain_id: str, member_ids: list) -> None:
|
||||||
"""清理测试数据"""
|
"""清理测试数据"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -283,7 +277,6 @@ def cleanup(tenant_id: str, domain_id: str, member_ids: list) -> None:
|
|||||||
manager.delete_tenant(tenant_id)
|
manager.delete_tenant(tenant_id)
|
||||||
print(f"✅ 租户已删除: {tenant_id}")
|
print(f"✅ 租户已删除: {tenant_id}")
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""主测试函数"""
|
"""主测试函数"""
|
||||||
print("\n" + " = " * 60)
|
print("\n" + " = " * 60)
|
||||||
@@ -321,6 +314,5 @@ def main() -> None:
|
|||||||
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() -> None:
|
def test_subscription_manager() -> None:
|
||||||
"""测试订阅管理器"""
|
"""测试订阅管理器"""
|
||||||
print(" = " * 60)
|
print(" = " * 60)
|
||||||
@@ -225,7 +224,6 @@ def test_subscription_manager() -> None:
|
|||||||
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() -> None:
|
def test_custom_model() -> None:
|
||||||
"""测试自定义模型功能"""
|
"""测试自定义模型功能"""
|
||||||
print("\n=== 测试自定义模型 ===")
|
print("\n=== 测试自定义模型 ===")
|
||||||
@@ -88,7 +87,6 @@ def test_custom_model() -> None:
|
|||||||
|
|
||||||
return model.id
|
return model.id
|
||||||
|
|
||||||
|
|
||||||
async def test_train_and_predict(model_id: str) -> None:
|
async def test_train_and_predict(model_id: str) -> None:
|
||||||
"""测试训练和预测"""
|
"""测试训练和预测"""
|
||||||
print("\n=== 测试模型训练和预测 ===")
|
print("\n=== 测试模型训练和预测 ===")
|
||||||
@@ -115,7 +113,6 @@ async def test_train_and_predict(model_id: str) -> None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" 预测失败: {e}")
|
print(f" 预测失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
def test_prediction_models() -> None:
|
def test_prediction_models() -> None:
|
||||||
"""测试预测模型"""
|
"""测试预测模型"""
|
||||||
print("\n=== 测试预测模型 ===")
|
print("\n=== 测试预测模型 ===")
|
||||||
@@ -157,7 +154,6 @@ def test_prediction_models() -> None:
|
|||||||
|
|
||||||
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) -> None:
|
async def test_predictions(trend_model_id: str, anomaly_model_id: str) -> None:
|
||||||
"""测试预测功能"""
|
"""测试预测功能"""
|
||||||
print("\n=== 测试预测功能 ===")
|
print("\n=== 测试预测功能 ===")
|
||||||
@@ -194,7 +190,6 @@ async def test_predictions(trend_model_id: str, anomaly_model_id: str) -> None:
|
|||||||
)
|
)
|
||||||
print(f" 检测结果: {anomaly_result.prediction_data}")
|
print(f" 检测结果: {anomaly_result.prediction_data}")
|
||||||
|
|
||||||
|
|
||||||
def test_kg_rag() -> None:
|
def test_kg_rag() -> None:
|
||||||
"""测试知识图谱 RAG"""
|
"""测试知识图谱 RAG"""
|
||||||
print("\n=== 测试知识图谱 RAG ===")
|
print("\n=== 测试知识图谱 RAG ===")
|
||||||
@@ -224,7 +219,6 @@ def test_kg_rag() -> None:
|
|||||||
|
|
||||||
return rag.id
|
return rag.id
|
||||||
|
|
||||||
|
|
||||||
async def test_kg_rag_query(rag_id: str) -> None:
|
async def test_kg_rag_query(rag_id: str) -> None:
|
||||||
"""测试 RAG 查询"""
|
"""测试 RAG 查询"""
|
||||||
print("\n=== 测试知识图谱 RAG 查询 ===")
|
print("\n=== 测试知识图谱 RAG 查询 ===")
|
||||||
@@ -295,7 +289,6 @@ async def test_kg_rag_query(rag_id: str) -> None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" 查询失败: {e}")
|
print(f" 查询失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
async def test_smart_summary() -> None:
|
async def test_smart_summary() -> None:
|
||||||
"""测试智能摘要"""
|
"""测试智能摘要"""
|
||||||
print("\n=== 测试智能摘要 ===")
|
print("\n=== 测试智能摘要 ===")
|
||||||
@@ -343,7 +336,6 @@ async def test_smart_summary() -> None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" 生成失败: {e}")
|
print(f" 生成失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
"""主测试函数"""
|
"""主测试函数"""
|
||||||
print(" = " * 60)
|
print(" = " * 60)
|
||||||
@@ -382,6 +374,5 @@ async def main() -> None:
|
|||||||
|
|
||||||
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 功能"""
|
||||||
|
|
||||||
@@ -739,12 +738,10 @@ class TestGrowthManager:
|
|||||||
print("✨ 测试完成!")
|
print("✨ 测试完成!")
|
||||||
print(" = " * 60)
|
print(" = " * 60)
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
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:
|
||||||
"""开发者生态系统测试类"""
|
"""开发者生态系统测试类"""
|
||||||
|
|
||||||
@@ -692,12 +691,10 @@ console.log('Upload complete:', result.id);
|
|||||||
|
|
||||||
print(" = " * 60)
|
print(" = " * 60)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
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:
|
||||||
"""测试运维与监控管理器"""
|
"""测试运维与监控管理器"""
|
||||||
|
|
||||||
@@ -244,7 +243,6 @@ class TestOpsManager:
|
|||||||
self.log("Recorded 10 resource metrics")
|
self.log("Recorded 10 resource metrics")
|
||||||
|
|
||||||
# 手动创建告警
|
# 手动创建告警
|
||||||
from ops_manager import Alert
|
|
||||||
|
|
||||||
alert_id = f"test_alert_{datetime.now().strftime('%Y%m%d%H%M%S')}"
|
alert_id = f"test_alert_{datetime.now().strftime('%Y%m%d%H%M%S')}"
|
||||||
now = datetime.now().isoformat()
|
now = datetime.now().isoformat()
|
||||||
@@ -733,12 +731,10 @@ class TestOpsManager:
|
|||||||
|
|
||||||
print(" = " * 60)
|
print(" = " * 60)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
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) -> None:
|
def __init__(self) -> None:
|
||||||
self.access_key = os.getenv("ALI_ACCESS_KEY", "")
|
self.access_key = os.getenv("ALI_ACCESS_KEY", "")
|
||||||
@@ -89,8 +88,6 @@ class TingwuClient:
|
|||||||
try:
|
try:
|
||||||
# 导入移到文件顶部会导致循环导入,保持在这里
|
# 导入移到文件顶部会导致循环导入,保持在这里
|
||||||
from alibabacloud_openapi_util import models as open_api_models
|
from alibabacloud_openapi_util import models as open_api_models
|
||||||
from alibabacloud_tingwu20230930 import models as tingwu_models
|
|
||||||
from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient
|
|
||||||
|
|
||||||
config = open_api_models.Config(
|
config = open_api_models.Config(
|
||||||
access_key_id=self.access_key,
|
access_key_id=self.access_key,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import hashlib
|
|||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import urllib.parse
|
|
||||||
import uuid
|
import uuid
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
@@ -39,7 +38,6 @@ DEFAULT_RETRY_DELAY = 5 # 默认重试延迟(秒)
|
|||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class WorkflowStatus(Enum):
|
class WorkflowStatus(Enum):
|
||||||
"""工作流状态"""
|
"""工作流状态"""
|
||||||
|
|
||||||
@@ -48,7 +46,6 @@ class WorkflowStatus(Enum):
|
|||||||
ERROR = "error"
|
ERROR = "error"
|
||||||
COMPLETED = "completed"
|
COMPLETED = "completed"
|
||||||
|
|
||||||
|
|
||||||
class WorkflowType(Enum):
|
class WorkflowType(Enum):
|
||||||
"""工作流类型"""
|
"""工作流类型"""
|
||||||
|
|
||||||
@@ -58,7 +55,6 @@ class WorkflowType(Enum):
|
|||||||
SCHEDULED_REPORT = "scheduled_report" # 定时报告
|
SCHEDULED_REPORT = "scheduled_report" # 定时报告
|
||||||
CUSTOM = "custom" # 自定义工作流
|
CUSTOM = "custom" # 自定义工作流
|
||||||
|
|
||||||
|
|
||||||
class WebhookType(Enum):
|
class WebhookType(Enum):
|
||||||
"""Webhook 类型"""
|
"""Webhook 类型"""
|
||||||
|
|
||||||
@@ -67,7 +63,6 @@ class WebhookType(Enum):
|
|||||||
SLACK = "slack"
|
SLACK = "slack"
|
||||||
CUSTOM = "custom"
|
CUSTOM = "custom"
|
||||||
|
|
||||||
|
|
||||||
class TaskStatus(Enum):
|
class TaskStatus(Enum):
|
||||||
"""任务执行状态"""
|
"""任务执行状态"""
|
||||||
|
|
||||||
@@ -77,7 +72,6 @@ class TaskStatus(Enum):
|
|||||||
FAILED = "failed"
|
FAILED = "failed"
|
||||||
CANCELLED = "cancelled"
|
CANCELLED = "cancelled"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WorkflowTask:
|
class WorkflowTask:
|
||||||
"""工作流任务定义"""
|
"""工作流任务定义"""
|
||||||
@@ -101,7 +95,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 配置"""
|
||||||
@@ -126,7 +119,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:
|
||||||
"""工作流定义"""
|
"""工作流定义"""
|
||||||
@@ -156,7 +148,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:
|
||||||
"""工作流执行日志"""
|
"""工作流执行日志"""
|
||||||
@@ -177,7 +168,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"""
|
||||||
|
|
||||||
@@ -335,7 +325,6 @@ class WebhookNotifier:
|
|||||||
"""关闭 HTTP 客户端"""
|
"""关闭 HTTP 客户端"""
|
||||||
await self.http_client.aclose()
|
await self.http_client.aclose()
|
||||||
|
|
||||||
|
|
||||||
class WorkflowManager:
|
class WorkflowManager:
|
||||||
"""工作流管理器 - 核心管理类"""
|
"""工作流管理器 - 核心管理类"""
|
||||||
|
|
||||||
@@ -1520,11 +1509,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
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ PROJECT_PATH = Path("/root/.openclaw/workspace/projects/insightflow")
|
|||||||
# 修复报告
|
# 修复报告
|
||||||
report = {"fixed": [], "manual_review": [], "errors": []}
|
report = {"fixed": [], "manual_review": [], "errors": []}
|
||||||
|
|
||||||
|
|
||||||
def find_python_files() -> list[Path]:
|
def find_python_files() -> list[Path]:
|
||||||
"""查找所有 Python 文件"""
|
"""查找所有 Python 文件"""
|
||||||
py_files = []
|
py_files = []
|
||||||
@@ -24,7 +23,6 @@ def find_python_files() -> list[Path]:
|
|||||||
py_files.append(py_file)
|
py_files.append(py_file)
|
||||||
return py_files
|
return py_files
|
||||||
|
|
||||||
|
|
||||||
def check_duplicate_imports(content: str, file_path: Path) -> list[dict]:
|
def check_duplicate_imports(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查重复导入"""
|
"""检查重复导入"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -47,7 +45,6 @@ def check_duplicate_imports(content: str, file_path: Path) -> list[dict]:
|
|||||||
imports[line_stripped] = i
|
imports[line_stripped] = i
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def check_bare_excepts(content: str, file_path: Path) -> list[dict]:
|
def check_bare_excepts(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查裸异常捕获"""
|
"""检查裸异常捕获"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -60,7 +57,6 @@ def check_bare_excepts(content: str, file_path: Path) -> list[dict]:
|
|||||||
issues.append({"line": i, "type": "bare_except", "content": stripped})
|
issues.append({"line": i, "type": "bare_except", "content": stripped})
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def check_line_length(content: str, file_path: Path) -> list[dict]:
|
def check_line_length(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查行长度(PEP8: 79字符,这里放宽到 100)"""
|
"""检查行长度(PEP8: 79字符,这里放宽到 100)"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -78,7 +74,6 @@ def check_line_length(content: str, file_path: Path) -> list[dict]:
|
|||||||
)
|
)
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def check_unused_imports(content: str, file_path: Path) -> list[dict]:
|
def check_unused_imports(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查未使用的导入"""
|
"""检查未使用的导入"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -108,7 +103,6 @@ def check_unused_imports(content: str, file_path: Path) -> list[dict]:
|
|||||||
pass
|
pass
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def check_string_formatting(content: str, file_path: Path) -> list[dict]:
|
def check_string_formatting(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查混合字符串格式化(建议使用 f-string)"""
|
"""检查混合字符串格式化(建议使用 f-string)"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -133,7 +127,6 @@ def check_string_formatting(content: str, file_path: Path) -> list[dict]:
|
|||||||
)
|
)
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def check_magic_numbers(content: str, file_path: Path) -> list[dict]:
|
def check_magic_numbers(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查魔法数字"""
|
"""检查魔法数字"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -176,7 +169,6 @@ def check_magic_numbers(content: str, file_path: Path) -> list[dict]:
|
|||||||
)
|
)
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def check_sql_injection(content: str, file_path: Path) -> list[dict]:
|
def check_sql_injection(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查 SQL 注入风险"""
|
"""检查 SQL 注入风险"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -203,7 +195,6 @@ def check_sql_injection(content: str, file_path: Path) -> list[dict]:
|
|||||||
)
|
)
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def check_cors_config(content: str, file_path: Path) -> list[dict]:
|
def check_cors_config(content: str, file_path: Path) -> list[dict]:
|
||||||
"""检查 CORS 配置"""
|
"""检查 CORS 配置"""
|
||||||
issues = []
|
issues = []
|
||||||
@@ -221,7 +212,6 @@ def check_cors_config(content: str, file_path: Path) -> list[dict]:
|
|||||||
)
|
)
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def fix_bare_excepts(content: str) -> str:
|
def fix_bare_excepts(content: str) -> str:
|
||||||
"""修复裸异常捕获"""
|
"""修复裸异常捕获"""
|
||||||
lines = content.split("\n")
|
lines = content.split("\n")
|
||||||
@@ -239,7 +229,6 @@ def fix_bare_excepts(content: str) -> str:
|
|||||||
|
|
||||||
return "\n".join(new_lines)
|
return "\n".join(new_lines)
|
||||||
|
|
||||||
|
|
||||||
def fix_line_length(content: str) -> str:
|
def fix_line_length(content: str) -> str:
|
||||||
"""修复行长度问题(简单折行)"""
|
"""修复行长度问题(简单折行)"""
|
||||||
lines = content.split("\n")
|
lines = content.split("\n")
|
||||||
@@ -258,7 +247,6 @@ def fix_line_length(content: str) -> str:
|
|||||||
|
|
||||||
return "\n".join(new_lines)
|
return "\n".join(new_lines)
|
||||||
|
|
||||||
|
|
||||||
def analyze_file(file_path: Path) -> dict:
|
def analyze_file(file_path: Path) -> dict:
|
||||||
"""分析单个文件"""
|
"""分析单个文件"""
|
||||||
try:
|
try:
|
||||||
@@ -279,7 +267,6 @@ def analyze_file(file_path: Path) -> dict:
|
|||||||
|
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
def fix_file(file_path: Path, issues: dict) -> bool:
|
def fix_file(file_path: Path, issues: dict) -> bool:
|
||||||
"""自动修复文件问题"""
|
"""自动修复文件问题"""
|
||||||
try:
|
try:
|
||||||
@@ -299,7 +286,6 @@ def fix_file(file_path: Path, issues: dict) -> bool:
|
|||||||
report["errors"].append(f"{file_path}: {e}")
|
report["errors"].append(f"{file_path}: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def generate_report(all_issues: dict) -> str:
|
def generate_report(all_issues: dict) -> str:
|
||||||
"""生成修复报告"""
|
"""生成修复报告"""
|
||||||
lines = []
|
lines = []
|
||||||
@@ -368,7 +354,6 @@ def generate_report(all_issues: dict) -> str:
|
|||||||
|
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
def git_commit_and_push() -> None:
|
def git_commit_and_push() -> None:
|
||||||
"""提交并推送代码"""
|
"""提交并推送代码"""
|
||||||
try:
|
try:
|
||||||
@@ -410,7 +395,6 @@ def git_commit_and_push() -> None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"❌ 错误: {e}"
|
return f"❌ 错误: {e}"
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
print("🔍 开始代码审查...")
|
print("🔍 开始代码审查...")
|
||||||
@@ -448,6 +432,5 @@ def main() -> None:
|
|||||||
print("\n✅ 代码审查完成!")
|
print("\n✅ 代码审查完成!")
|
||||||
return report_content
|
return report_content
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import ast
|
|||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class CodeIssue:
|
class CodeIssue:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -27,7 +26,6 @@ class CodeIssue:
|
|||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"{self.severity.upper()}: {self.file_path}:{self.line_no} - {self.issue_type}: {self.message}"
|
return f"{self.severity.upper()}: {self.file_path}:{self.line_no} - {self.issue_type}: {self.message}"
|
||||||
|
|
||||||
|
|
||||||
class CodeReviewer:
|
class CodeReviewer:
|
||||||
def __init__(self, base_path: str) -> None:
|
def __init__(self, base_path: str) -> None:
|
||||||
self.base_path = Path(base_path)
|
self.base_path = Path(base_path)
|
||||||
@@ -422,7 +420,6 @@ class CodeReviewer:
|
|||||||
|
|
||||||
return "\n".join(report)
|
return "\n".join(report)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
base_path = "/root/.openclaw/workspace/projects/insightflow/backend"
|
base_path = "/root/.openclaw/workspace/projects/insightflow/backend"
|
||||||
reviewer = CodeReviewer(base_path)
|
reviewer = CodeReviewer(base_path)
|
||||||
@@ -447,6 +444,5 @@ def main() -> None:
|
|||||||
|
|
||||||
return reviewer
|
return reviewer
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user