""" POST /getScenes — 场景列表 """ from fastapi import APIRouter, Request from fastapi.responses import JSONResponse from services.scene_service import Scenes, prepare_scene_runtime from services.session_store import save_session router = APIRouter() @router.post("/getScenes") async def get_scenes(request: Request): try: scenes_list = [] for scene_name, data in Scenes.items(): scene_config, rtc_config, voice_chat = prepare_scene_runtime( scene_name, data ) scene_config["id"] = scene_name scene_config["botName"] = voice_chat.get("AgentConfig", {}).get("UserId") scene_config["isInterruptMode"] = ( voice_chat.get("Config", {}).get("InterruptMode") == 0 ) scene_config["isVision"] = ( voice_chat.get("Config", {}) .get("LLMConfig", {}) .get("VisionConfig", {}) .get("Enable") ) scene_config["isScreenMode"] = ( voice_chat.get("Config", {}) .get("LLMConfig", {}) .get("VisionConfig", {}) .get("SnapshotConfig", {}) .get("StreamType") == 1 ) scene_config["isAvatarScene"] = ( voice_chat.get("Config", {}).get("AvatarConfig", {}).get("Enabled") ) scene_config["avatarBgUrl"] = ( voice_chat.get("Config", {}) .get("AvatarConfig", {}) .get("BackgroundUrl") ) rtc_out = {k: v for k, v in rtc_config.items() if k != "AppKey"} rtc_out["TaskId"] = voice_chat.get("TaskId", "") # 存储本次生成的房间信息,供后续 StartVoiceChat 使用 save_session(request, scene_name, { "RoomId": rtc_config.get("RoomId", ""), "UserId": rtc_config.get("UserId", ""), "TaskId": voice_chat.get("TaskId", ""), }) scenes_list.append( { "scene": scene_config, "rtc": rtc_out, } ) return JSONResponse( { "ResponseMetadata": {"Action": "getScenes"}, "Result": {"scenes": scenes_list}, } ) except ValueError as e: return JSONResponse( { "ResponseMetadata": { "Action": "getScenes", "Error": {"Code": -1, "Message": str(e)}, } } )