fix: execute mode cards through deterministic assistant route
This commit is contained in:
@@ -377,6 +377,65 @@ def _catalog_exact_mode_match_count(
|
||||
return len(matched_ids)
|
||||
|
||||
|
||||
def _catalog_exact_mode_execution_id(
|
||||
catalog: Mapping[str, object],
|
||||
message: str,
|
||||
) -> str | None:
|
||||
"""Resolve an explicit saved-mode run without asking the model to route it."""
|
||||
|
||||
source_status = catalog.get("source_status")
|
||||
if not isinstance(source_status, Mapping) or source_status.get("modes") != "ready":
|
||||
return None
|
||||
|
||||
normalized = re.sub(r"[\s,。!?!?、;;::]", "", str(message).casefold())
|
||||
if not normalized:
|
||||
return None
|
||||
prefixes = ("", "请", "请帮我", "帮我", "麻烦", "麻烦帮我", "现在", "立即", "马上")
|
||||
verbs = ("进入", "启动", "执行", "开启", "打开", "切换到")
|
||||
suffixes = ("", "吧", "一下", "现在", "立即")
|
||||
matched_ids: set[str] = set()
|
||||
raw_modes = catalog.get("modes", [])
|
||||
if not isinstance(raw_modes, Sequence) or isinstance(
|
||||
raw_modes,
|
||||
(str, bytes, bytearray),
|
||||
):
|
||||
return None
|
||||
for raw_mode in raw_modes:
|
||||
if not isinstance(raw_mode, Mapping) or raw_mode.get("assistant_callable") is not True:
|
||||
continue
|
||||
mode_id = str(raw_mode.get("id") or "").strip()
|
||||
if not mode_id:
|
||||
continue
|
||||
aliases = raw_mode.get("aliases", [])
|
||||
candidates = [
|
||||
raw_mode.get("name"),
|
||||
*(
|
||||
aliases
|
||||
if isinstance(aliases, Sequence)
|
||||
and not isinstance(aliases, (str, bytes, bytearray))
|
||||
else []
|
||||
),
|
||||
]
|
||||
for candidate in candidates:
|
||||
mode_name = re.sub(
|
||||
r"[\s,。!?!?、;;::]",
|
||||
"",
|
||||
str(candidate or "").casefold(),
|
||||
)
|
||||
if not mode_name:
|
||||
continue
|
||||
accepted = {
|
||||
f"{prefix}{verb}{mode_name}{suffix}"
|
||||
for prefix in prefixes
|
||||
for verb in verbs
|
||||
for suffix in suffixes
|
||||
}
|
||||
if normalized in accepted:
|
||||
matched_ids.add(mode_id)
|
||||
break
|
||||
return next(iter(matched_ids)) if len(matched_ids) == 1 else None
|
||||
|
||||
|
||||
def _catalog_exact_scene_template_plan(
|
||||
catalog: Mapping[str, object],
|
||||
requested_name: str,
|
||||
@@ -822,6 +881,12 @@ class CodexAssistantService:
|
||||
control_terms,
|
||||
draft_context,
|
||||
)
|
||||
saved_mode_execution_id = _catalog_exact_mode_execution_id(catalog, message)
|
||||
if saved_mode_execution_id is not None:
|
||||
authorization = _VehicleAuthorization(
|
||||
message,
|
||||
"explicit_saved_mode_execute",
|
||||
)
|
||||
fast_comfort_control = (
|
||||
self._fast_implicit_controls and authorization.reason in _FAST_COMFORT_REASONS
|
||||
)
|
||||
@@ -877,6 +942,7 @@ class CodexAssistantService:
|
||||
direct_vehicle_control = (
|
||||
fast_comfort_control
|
||||
or exact_quick_control
|
||||
or saved_mode_execution_id is not None
|
||||
or direct_mode_profile_preview
|
||||
or authorization.reason == "explicit_mode_profile_draft_update"
|
||||
or saved_mode_management_route is not None
|
||||
@@ -890,6 +956,8 @@ class CodexAssistantService:
|
||||
if scene_template_plan is not None
|
||||
else saved_mode_management_route
|
||||
if saved_mode_management_route is not None
|
||||
else "mode_profile_execute"
|
||||
if saved_mode_execution_id is not None
|
||||
else "vehicle_control"
|
||||
if direct_vehicle_control
|
||||
else "scene_composer"
|
||||
@@ -905,6 +973,8 @@ class CodexAssistantService:
|
||||
if direct_mode_profile_preview or direct_mode_profile_update
|
||||
else "n7web-mode-profile-manager"
|
||||
if saved_mode_management_route is not None
|
||||
else "n7web-mode-profile-runner"
|
||||
if saved_mode_execution_id is not None
|
||||
else "codex-app-server-scene-composer"
|
||||
if scene_composition_preview
|
||||
else "n7web-control-router"
|
||||
@@ -944,6 +1014,8 @@ class CodexAssistantService:
|
||||
if saved_mode_management_route == "mode_profile_update"
|
||||
else "正在删除自定义功能模式……"
|
||||
if saved_mode_management_route == "mode_profile_delete"
|
||||
else "正在载入并执行已保存的功能模式……"
|
||||
if saved_mode_execution_id is not None
|
||||
else "正在根据实时能力目录快速组合模式……"
|
||||
if scene_composition_preview
|
||||
else "小迪正在理解场景并组合工程能力……"
|
||||
@@ -1039,6 +1111,8 @@ class CodexAssistantService:
|
||||
if scene_template_plan is not None
|
||||
else saved_mode_management_route
|
||||
if saved_mode_management_route is not None
|
||||
else "mode_profile_execute"
|
||||
if saved_mode_execution_id is not None
|
||||
else "vehicle_control"
|
||||
),
|
||||
)
|
||||
@@ -1679,6 +1753,7 @@ class CodexAssistantService:
|
||||
authorization.reason == "explicit_mode_profile_draft_update"
|
||||
)
|
||||
exact_quick_control = authorization.reason == "exact_quick_control"
|
||||
saved_mode_execution = authorization.reason == "explicit_saved_mode_execute"
|
||||
mode_profile_management_route = {
|
||||
"explicit_mode_profile_update": "mode_profile_update",
|
||||
"explicit_mode_profile_delete": "mode_profile_delete",
|
||||
@@ -1697,6 +1772,8 @@ class CodexAssistantService:
|
||||
if mode_profile_management_route == "mode_profile_update"
|
||||
else "正在删除自定义功能模式……"
|
||||
if mode_profile_management_route == "mode_profile_delete"
|
||||
else "正在通过安全执行链进入功能模式……"
|
||||
if saved_mode_execution
|
||||
else "正在通过车辆安全链执行快捷控制……"
|
||||
if exact_quick_control
|
||||
else "正在通过车辆安全链执行舒适性调节……"
|
||||
@@ -1721,6 +1798,8 @@ class CodexAssistantService:
|
||||
"display_text": (
|
||||
"模式动作已解析,正在进行安全校验……"
|
||||
if mode_profile_preview
|
||||
else "已保存模式动作已载入,正在校验并执行……"
|
||||
if saved_mode_execution
|
||||
else "功能模式存储请求已解析,正在校验……"
|
||||
if mode_profile_management_route is not None
|
||||
else "控制指令已通过校验,正在执行……"
|
||||
@@ -1814,6 +1893,14 @@ class CodexAssistantService:
|
||||
if mode_profile_preview
|
||||
else completion_text
|
||||
if mode_profile_management_route is not None
|
||||
else "功能模式已提交,等待车辆状态确认"
|
||||
if saved_mode_execution and action_state == "submitted"
|
||||
else "功能模式模拟编排已完成"
|
||||
if saved_mode_execution and action_state == "simulated"
|
||||
else "功能模式执行已完成"
|
||||
if saved_mode_execution and successful
|
||||
else "功能模式执行未完成"
|
||||
if saved_mode_execution
|
||||
else "快捷控制已提交,等待车辆状态确认"
|
||||
if exact_quick_control and action_state == "submitted"
|
||||
else "快捷控制模拟编排已完成"
|
||||
@@ -2164,11 +2251,18 @@ class CodexAssistantService:
|
||||
result: Mapping[str, object],
|
||||
successful: bool,
|
||||
) -> str:
|
||||
if reason == "exact_quick_control":
|
||||
if reason in {"exact_quick_control", "explicit_saved_mode_execute"}:
|
||||
instruction = re.sub(
|
||||
r"\s+",
|
||||
" ",
|
||||
str(result.get("utterance") or "快捷控制指令"),
|
||||
str(
|
||||
result.get("utterance")
|
||||
or (
|
||||
"功能模式"
|
||||
if reason == "explicit_saved_mode_execute"
|
||||
else "快捷控制指令"
|
||||
)
|
||||
),
|
||||
).strip()[:160]
|
||||
if not successful:
|
||||
return f"未能完成“{instruction}”,请检查车辆状态后重试。"
|
||||
|
||||
Reference in New Issue
Block a user