refactor(memory-api): migrate end user creation to authenticated API endpoint

- Remove unauthenticated end_user_controller and its router registration
- Move end user creation logic to authenticated memory_api_controller endpoint
- Add create_end_user method to MemoryAPIService with workspace authorization
- Fix retrieve_nodes import in read_graph to use correct function reference
- Consolidate end user management under authenticated memory API with API key scoping
This commit is contained in:
Ke Sun
2026-03-26 20:12:11 +08:00
parent 3ed6f49bb0
commit a5bce221bd
5 changed files with 80 additions and 53 deletions

View File

@@ -280,6 +280,53 @@ class MemoryAPIService:
code=BizCode.MEMORY_READ_FAILED
)
def create_end_user(
self,
workspace_id: uuid.UUID,
other_id: str,
) -> Dict[str, Any]:
"""Create or retrieve an end user for the workspace.
Uses get_or_create semantics: if an end user with the same other_id
already exists in the workspace, returns the existing one.
Args:
workspace_id: Workspace ID from API key authorization
other_id: External user identifier
Returns:
Dict with id, other_id, other_name, and workspace_id
Raises:
BusinessException: If creation fails
"""
logger.info(f"Creating end user - other_id: {other_id}, workspace_id: {workspace_id}")
try:
from app.repositories.end_user_repository import EndUserRepository
end_user_repo = EndUserRepository(self.db)
end_user = end_user_repo.get_or_create_end_user(
app_id=None,
workspace_id=workspace_id,
other_id=other_id,
)
logger.info(f"End user ready: {end_user.id}")
return {
"id": str(end_user.id),
"other_id": end_user.other_id or "",
"other_name": end_user.other_name or "",
"workspace_id": str(end_user.workspace_id),
}
except Exception as e:
logger.error(f"Failed to create end user for workspace {workspace_id}: {e}")
raise BusinessException(
message=f"Failed to create end user: {str(e)}",
code=BizCode.INTERNAL_ERROR
)
def list_memory_configs(
self,
workspace_id: uuid.UUID,