1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| 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。打开翻译、打开英语学习/复读、回到聊天、退出翻译时调用。app_id 只能是 chat、english_learning、english_translation。",
| "parameters": {
| "type": "object",
| "properties": {
| "app_id": {
| "type": "string",
| "description": "目标 App:chat(聊天)、english_learning(复读)、english_translation(翻译)",
| }
| },
| "required": ["app_id"],
| },
| },
| }
|
|
| @register_function("switch_app", switch_app_function_desc, ToolType.SYSTEM_CTL)
| async def switch_app(conn: "ConnectionHandler", app_id: str):
| from core.app_runtime.runtime import switch_app as runtime_switch
|
| result = await runtime_switch(conn, app_id, source="voice")
| 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)
|
|