Fix/interface home (#182)
* [fix]Fix the interface for statistics of recent activities and applications * [changes]Modify the code based on the AI review 1.Use the boolean auxiliary methods provided by SQLAlchemy instead of using == True in the is_active filter. 2.The calculation of the "PROJECT_ROOT" has now been hardcoded with five levels of nested os.path.dirname calls. * [fix]Fix the interface for statistics of recent activities and applications * [changes]Modify the code based on the AI review 1.Use the boolean auxiliary methods provided by SQLAlchemy instead of using == True in the is_active filter. 2.The calculation of the "PROJECT_ROOT" has now been hardcoded with five levels of nested os.path.dirname calls.
This commit is contained in:
@@ -55,8 +55,8 @@ class AgentRegistry:
|
||||
"""
|
||||
# 构建查询
|
||||
stmt = select(AgentConfig).join(App).where(
|
||||
AgentConfig.is_active == True,
|
||||
App.is_active == True
|
||||
AgentConfig.is_active.is_(True),
|
||||
App.is_active.is_(True)
|
||||
)
|
||||
|
||||
# 工作空间过滤(同工作空间或公开)
|
||||
|
||||
@@ -758,7 +758,7 @@ class AppService:
|
||||
)
|
||||
|
||||
# 构建查询条件
|
||||
filters = [App.is_active == True]
|
||||
filters = [App.is_active.is_(True)]
|
||||
if type:
|
||||
filters.append(App.type == type)
|
||||
if visibility:
|
||||
@@ -873,7 +873,7 @@ class AppService:
|
||||
|
||||
self._validate_workspace_access(app, workspace_id)
|
||||
|
||||
stmt = select(AgentConfig).where(AgentConfig.app_id == app_id, AgentConfig.is_active == True).order_by(
|
||||
stmt = select(AgentConfig).where(AgentConfig.app_id == app_id, AgentConfig.is_active.is_(True)).order_by(
|
||||
AgentConfig.updated_at.desc())
|
||||
agent_cfg: Optional[AgentConfig] = self.db.scalars(stmt).first()
|
||||
now = datetime.datetime.now()
|
||||
@@ -1204,7 +1204,7 @@ class AppService:
|
||||
default_model_config_id = None
|
||||
|
||||
if app.type == AppType.AGENT:
|
||||
stmt = select(AgentConfig).where(AgentConfig.app_id == app_id, AgentConfig.is_active == True).order_by(
|
||||
stmt = select(AgentConfig).where(AgentConfig.app_id == app_id, AgentConfig.is_active.is_(True)).order_by(
|
||||
AgentConfig.updated_at.desc())
|
||||
agent_cfg = self.db.scalars(stmt).first()
|
||||
if not agent_cfg:
|
||||
@@ -1226,7 +1226,7 @@ class AppService:
|
||||
select(MultiAgentConfig)
|
||||
.where(
|
||||
MultiAgentConfig.app_id == app_id,
|
||||
MultiAgentConfig.is_active == True
|
||||
MultiAgentConfig.is_active.is_(True)
|
||||
)
|
||||
.order_by(MultiAgentConfig.updated_at.desc())
|
||||
)
|
||||
@@ -1380,7 +1380,7 @@ class AppService:
|
||||
|
||||
stmt = (
|
||||
select(AppRelease)
|
||||
.where(AppRelease.app_id == app_id, AppRelease.is_active == True)
|
||||
.where(AppRelease.app_id == app_id, AppRelease.is_active.is_(True))
|
||||
.order_by(AppRelease.version.desc())
|
||||
)
|
||||
return list(self.db.scalars(stmt).all())
|
||||
|
||||
@@ -728,7 +728,7 @@ class DraftRunService:
|
||||
select(ModelApiKey)
|
||||
.where(
|
||||
ModelApiKey.model_config_id == model_config_id,
|
||||
ModelApiKey.is_active == True
|
||||
ModelApiKey.is_active.is_(True)
|
||||
)
|
||||
.order_by(ModelApiKey.priority.desc())
|
||||
.limit(1)
|
||||
|
||||
@@ -173,10 +173,9 @@ class MemoryAgentService:
|
||||
"""
|
||||
logger.info("Reading log file")
|
||||
|
||||
|
||||
current_file = os.path.abspath(__file__) # app/services/memory_agent_service.py
|
||||
app_dir = os.path.dirname(os.path.dirname(current_file)) # app directory
|
||||
project_root = os.path.dirname(app_dir) # redbear-mem directory
|
||||
# Get log file path - use project root directory
|
||||
from pathlib import Path
|
||||
project_root = str(Path(__file__).resolve().parents[2]) # api directory
|
||||
log_path = os.path.join(project_root, "logs", "agent_service.log")
|
||||
|
||||
summer = ''
|
||||
@@ -215,9 +214,8 @@ class MemoryAgentService:
|
||||
logger.info("Starting log content streaming")
|
||||
|
||||
# Get log file path - use project root directory
|
||||
current_file = os.path.abspath(__file__) # app/services/memory_agent_service.py
|
||||
app_dir = os.path.dirname(os.path.dirname(current_file)) # app directory
|
||||
project_root = os.path.dirname(app_dir) # redbear-mem directory
|
||||
from pathlib import Path
|
||||
project_root = str(Path(__file__).resolve().parents[2]) # api directory
|
||||
log_path = os.path.join(project_root, "logs", "agent_service.log")
|
||||
|
||||
# Check if file exists before starting stream
|
||||
@@ -1079,9 +1077,8 @@ class MemoryAgentService:
|
||||
logger.info("Starting log content streaming")
|
||||
|
||||
# Get log file path - use project root directory
|
||||
current_file = os.path.abspath(__file__) # app/services/memory_agent_service.py
|
||||
app_dir = os.path.dirname(os.path.dirname(current_file)) # app directory
|
||||
project_root = os.path.dirname(app_dir) # redbear-mem directory
|
||||
from pathlib import Path
|
||||
project_root = str(Path(__file__).resolve().parents[2]) # api directory
|
||||
log_path = os.path.join(project_root, "logs", "agent_service.log")
|
||||
|
||||
# Check if file exists before starting stream
|
||||
|
||||
@@ -77,7 +77,10 @@ class MemoryAPIService:
|
||||
)
|
||||
|
||||
# Verify end_user belongs to the workspace via App relationship
|
||||
app = self.db.query(App).filter(App.id == end_user.app_id).first()
|
||||
app = self.db.query(App).filter(
|
||||
App.id == end_user.app_id,
|
||||
App.is_active.is_(True)
|
||||
).first()
|
||||
|
||||
if not app:
|
||||
logger.warning(f"App not found for end_user: {end_user_id}")
|
||||
|
||||
@@ -38,7 +38,10 @@ class WorkspaceAppService:
|
||||
Returns:
|
||||
Dictionary containing detailed application information
|
||||
"""
|
||||
apps = self.db.query(App).filter(App.workspace_id == workspace_id).all()
|
||||
apps = self.db.query(App).filter(
|
||||
App.workspace_id == workspace_id,
|
||||
App.is_active.is_(True)
|
||||
).all()
|
||||
app_ids = [str(app.id) for app in apps]
|
||||
|
||||
apps_detailed_info = []
|
||||
|
||||
@@ -237,7 +237,8 @@ class DataConfigService: # 数据配置服务类(PostgreSQL)
|
||||
ValueError: 当配置无效或参数缺失时
|
||||
RuntimeError: 当管线执行失败时
|
||||
"""
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from pathlib import Path
|
||||
project_root = str(Path(__file__).resolve().parents[2])
|
||||
|
||||
try:
|
||||
# 发出初始进度事件
|
||||
|
||||
@@ -2548,7 +2548,7 @@ class MultiAgentOrchestrator:
|
||||
# 获取 API Key 配置
|
||||
api_key_config = self.db.query(ModelApiKey).filter(
|
||||
ModelApiKey.model_config_id == default_model_config_id,
|
||||
ModelApiKey.is_active == True
|
||||
ModelApiKey.is_active.is_(True)
|
||||
).first()
|
||||
|
||||
if not api_key_config:
|
||||
@@ -2705,7 +2705,7 @@ class MultiAgentOrchestrator:
|
||||
# 获取 API Key 配置
|
||||
api_key_config = self.db.query(ModelApiKey).filter(
|
||||
ModelApiKey.model_config_id == default_model_config_id,
|
||||
ModelApiKey.is_active == True
|
||||
ModelApiKey.is_active.is_(True)
|
||||
).first()
|
||||
|
||||
if not api_key_config:
|
||||
|
||||
@@ -74,7 +74,7 @@ class MultiAgentService:
|
||||
select(MultiAgentConfig)
|
||||
.where(
|
||||
MultiAgentConfig.app_id == app_id,
|
||||
MultiAgentConfig.is_active == True
|
||||
MultiAgentConfig.is_active.is_(True)
|
||||
)
|
||||
.order_by(MultiAgentConfig.updated_at.desc())
|
||||
).first()
|
||||
@@ -144,7 +144,7 @@ class MultiAgentService:
|
||||
select(MultiAgentConfig)
|
||||
.where(
|
||||
MultiAgentConfig.app_id == app_id,
|
||||
MultiAgentConfig.is_active == True
|
||||
MultiAgentConfig.is_active.is_(True)
|
||||
)
|
||||
.order_by(MultiAgentConfig.updated_at.desc())
|
||||
).first()
|
||||
|
||||
@@ -168,7 +168,7 @@ class SharedChatService:
|
||||
select(ModelApiKey)
|
||||
.where(
|
||||
ModelApiKey.model_config_id == model_config_id,
|
||||
ModelApiKey.is_active == True
|
||||
ModelApiKey.is_active.is_(True)
|
||||
)
|
||||
.order_by(ModelApiKey.priority.desc())
|
||||
.limit(1)
|
||||
@@ -362,7 +362,7 @@ class SharedChatService:
|
||||
select(ModelApiKey)
|
||||
.where(
|
||||
ModelApiKey.model_config_id == model_config_id,
|
||||
ModelApiKey.is_active == True
|
||||
ModelApiKey.is_active.is_(True)
|
||||
)
|
||||
.order_by(ModelApiKey.priority.desc())
|
||||
.limit(1)
|
||||
@@ -598,7 +598,7 @@ class SharedChatService:
|
||||
# 获取多 Agent 配置
|
||||
multi_agent_config = self.db.query(MultiAgentConfig).filter(
|
||||
MultiAgentConfig.app_id == release.app_id,
|
||||
MultiAgentConfig.is_active == True
|
||||
MultiAgentConfig.is_active.is_(True)
|
||||
).first()
|
||||
|
||||
if not multi_agent_config:
|
||||
@@ -695,7 +695,7 @@ class SharedChatService:
|
||||
# 获取多 Agent 配置
|
||||
multi_agent_config = self.db.query(MultiAgentConfig).filter(
|
||||
MultiAgentConfig.app_id == release.app_id,
|
||||
MultiAgentConfig.is_active == True
|
||||
MultiAgentConfig.is_active.is_(True)
|
||||
).first()
|
||||
|
||||
if not multi_agent_config:
|
||||
|
||||
@@ -761,7 +761,10 @@ class WorkflowService:
|
||||
|
||||
# 4. 获取工作空间 ID(从 app 获取)
|
||||
from app.models import App
|
||||
app = self.db.query(App).filter(App.id == app_id).first()
|
||||
app = self.db.query(App).filter(
|
||||
App.id == app_id,
|
||||
App.is_active.is_(True)
|
||||
).first()
|
||||
if not app:
|
||||
raise BusinessException(
|
||||
code=BizCode.NOT_FOUND,
|
||||
|
||||
Reference in New Issue
Block a user