diff --git a/phone_agent/actions/handler.py b/phone_agent/actions/handler.py index 0bef1c3a..20a6e6d8 100644 --- a/phone_agent/actions/handler.py +++ b/phone_agent/actions/handler.py @@ -9,6 +9,7 @@ from phone_agent.config.timing import TIMING_CONFIG from phone_agent.device_factory import get_device_factory +from phone_agent.utils import regex_util @dataclass @@ -358,7 +359,7 @@ def parse_action(response: str) -> dict[str, Any]: response = response.replace('\n', '\\n') response = response.replace('\r', '\\r') response = response.replace('\t', '\\t') - + response = regex_util.escape_inner_quotes(response) tree = ast.parse(response, mode="eval") if not isinstance(tree.body, ast.Call): raise ValueError("Expected a function call") diff --git a/phone_agent/utils/regex_util.py b/phone_agent/utils/regex_util.py new file mode 100644 index 00000000..59850cc5 --- /dev/null +++ b/phone_agent/utils/regex_util.py @@ -0,0 +1,21 @@ +import re + +def escape_inner_quotes(expr: str) -> str: + """ + 解析指令字符串,转义 value 内部嵌套的、未转义的双引号。 + 使用正向断言确保只匹配真正的结构化引号。 + """ + def repl(match): + key = match.group(1) + val = match.group(2) + # 核心修复:把 value 内部「前面没有斜杠」的双引号加上斜杠 + # 比如:把 [输入了""] 变成 [输入了\"\"] + fixed_val = re.sub(r'(?