fix(app): memory config initialization for end users

- Add memory_config_id extraction and assignment when creating new end users in public share chat
- Introduce get_or_create_end_user_with_config method to handle memory config setup in single transaction
- Add batch_update_memory_config_id_by_app method for bulk updating end user memory configs
- Rename _update_endusers_memory_config_by_workspace to _update_endusers_memory_config_by_app for correct scope
- Update app publish flow to use app_id instead of workspace_id for memory config updates
- Remove unused actual_end_user_id variable in langchain_agent
- Ensures end users are properly associated with memory configs on creation and during app updates
This commit is contained in:
Ke Sun
2026-03-30 16:44:43 +08:00
parent e3dcbed5f9
commit f7e89af9d2
4 changed files with 139 additions and 9 deletions

View File

@@ -1682,15 +1682,15 @@ class AppService:
return config.config_id
def _update_endusers_memory_config_by_workspace(
def _update_endusers_memory_config_by_app(
self,
workspace_id: uuid.UUID,
app_id: uuid.UUID,
memory_config_id: uuid.UUID
) -> int:
"""批量更新应用下所有终端用户的 memory_config_id
Args:
workspace_id: 工作空间ID
app_id: 应用ID
memory_config_id: 新的记忆配置ID
Returns:
@@ -1699,8 +1699,8 @@ class AppService:
from app.repositories.end_user_repository import EndUserRepository
repo = EndUserRepository(self.db)
updated_count = repo.batch_update_memory_config_id_by_workspace(
workspace_id=workspace_id,
updated_count = repo.batch_update_memory_config_id_by_app(
app_id=app_id,
memory_config_id=memory_config_id
)
@@ -1879,8 +1879,8 @@ class AppService:
if memory_config_id:
app = self.db.query(App).filter(App.id == app_id).first()
if app:
updated_count = self._update_endusers_memory_config_by_workspace(
app.workspace_id, memory_config_id
updated_count = self._update_endusers_memory_config_by_app(
app_id, memory_config_id
)
logger.info(
f"发布时更新终端用户记忆配置: app_id={app_id}, workspace_id={app.workspace_id}, "
@@ -2016,7 +2016,7 @@ class AppService:
if memory_config_id:
updated_count = self._update_endusers_memory_config_by_workspace(app.workspace_id, memory_config_id)
updated_count = self._update_endusers_memory_config_by_app(app_id, memory_config_id)
logger.info(
f"回滚时更新终端用户记忆配置: app_id={app_id}, version={version}, "
f"memory_config_id={memory_config_id}, updated_count={updated_count}"