from typing import TYPE_CHECKING from plugins_func.register import register_function, ToolType, ActionResponse, Action if TYPE_CHECKING: from core.connection import ConnectionHandler switch_app_function_desc = { "type": "function", "function": { "name": "switch_app", "description": ( "切换设备当前 App。" "chat=对话;english_translation=翻译;english_conversation=中英对话;" "english_learning 需配合 task_id:repeater=泛听,shadowing=跟读。" "语音切换泛听/跟读时执行家长上次下发的课文,没有上次课文则提示先选课。" "退出当前模式、回到聊天时 app_id=chat。" ), "parameters": { "type": "object", "properties": { "app_id": { "type": "string", "description": "chat、english_learning、english_translation、english_conversation", }, "task_id": { "type": "string", "description": "可选。english_learning 下 repeater 或 shadowing;其它 App 可空", }, }, "required": ["app_id"], }, }, } @register_function("switch_app", switch_app_function_desc, ToolType.SYSTEM_CTL) async def switch_app(conn: "ConnectionHandler", app_id: str, task_id: str = ""): from core.app_runtime.runtime import switch_app as runtime_switch result = await runtime_switch(conn, app_id, source="voice", task_id=task_id or "") if result.action == Action.ERROR: return ActionResponse( action=Action.RESPONSE, result=result.response, response=result.response or "打不开这个应用", ) if str(result.result or "").startswith("chat/"): return ActionResponse(action=Action.NONE, result=result.result, response=result.response) name = result.response or "已切换" return ActionResponse(action=Action.RESPONSE, result=result.result, response=name)