Skip to content

Commit 70fe992

Browse files
committed
feat(topics): Enhance topic model with moderator mode attributes and integration
- Added `moderator_mode_id` and `moderator_mode_name` fields to the Topic model for better moderator mode handling. - Implemented `_augment_topic_with_moderator_mode` function to populate moderator mode details from workspace configuration. - Updated `get_topics` and `get_topic_detail` endpoints to utilize the new function, ensuring topics are enriched with moderator mode information before returning.
1 parent 0685432 commit 70fe992

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

app/api/topics.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from fastapi import APIRouter, HTTPException
44

5+
from app.agent.moderator_modes import PRESET_MODES, load_moderator_mode_config
56
from app.agent.workspace import ensure_topic_workspace, read_discussion_history
67
from app.core.config import get_workspace_base
78
from app.models.schemas import (
@@ -22,9 +23,30 @@
2223
router = APIRouter()
2324

2425

26+
def _augment_topic_with_moderator_mode(topic: Topic) -> Topic:
27+
"""Add moderator_mode_id and moderator_mode_name from workspace config."""
28+
try:
29+
ws_base = get_workspace_base()
30+
ws_path = ws_base / "topics" / topic.id
31+
cfg = load_moderator_mode_config(ws_path)
32+
mode_id = cfg.get("mode_id", "standard")
33+
topic.moderator_mode_id = mode_id
34+
if mode_id == "custom":
35+
topic.moderator_mode_name = "自定义模式"
36+
else:
37+
topic.moderator_mode_name = PRESET_MODES.get(mode_id, {}).get("name", mode_id)
38+
except Exception:
39+
topic.moderator_mode_id = "standard"
40+
topic.moderator_mode_name = PRESET_MODES.get("standard", {}).get("name", "Standard Round Table")
41+
return topic
42+
43+
2544
@router.get("", response_model=list[Topic])
2645
def get_topics():
27-
return list_topics()
46+
topics = list_topics()
47+
for t in topics:
48+
_augment_topic_with_moderator_mode(t)
49+
return topics
2850

2951

3052
@router.post("", response_model=Topic, status_code=201)
@@ -39,6 +61,8 @@ def post_topic(data: TopicCreate):
3961
@router.get("/{topic_id}", response_model=Topic)
4062
def get_topic_detail(topic_id: str):
4163
topic = get_topic(topic_id)
64+
if topic:
65+
_augment_topic_with_moderator_mode(topic)
4266
if not topic:
4367
raise HTTPException(status_code=404, detail="Topic not found")
4468

app/models/schemas.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class Topic(BaseModel):
7171
discussion_status: DiscussionStatus = DiscussionStatus.PENDING
7272
created_at: str
7373
updated_at: str
74+
# Populated by API from config/moderator_mode.json (not in topic.json)
75+
moderator_mode_id: Optional[str] = None
76+
moderator_mode_name: Optional[str] = None
7477

7578

7679
# --- Comment models ---

0 commit comments

Comments
 (0)