fix: harden conversational mode draft revisions
This commit is contained in:
@@ -4309,7 +4309,7 @@ class SeatDemoService:
|
||||
if not change_text:
|
||||
raise ValueError("请说明要调整的设备和明确目标值。")
|
||||
parseable_change_text = re.sub(
|
||||
r"改为|改成|变更为|换成|变为",
|
||||
r"改为|改成|变更为|换成|变成|变为",
|
||||
"调整为",
|
||||
change_text,
|
||||
)
|
||||
@@ -4387,6 +4387,22 @@ class SeatDemoService:
|
||||
): item
|
||||
for item in normalized_changes
|
||||
}
|
||||
base_by_key = {
|
||||
(
|
||||
str(item["domain"]),
|
||||
str(item["capability"]),
|
||||
str(item["target_scope"]),
|
||||
): item
|
||||
for item in base_operations
|
||||
}
|
||||
requested_operation_count = len(change_by_key)
|
||||
changed_operation_count = sum(
|
||||
1
|
||||
for key, item in change_by_key.items()
|
||||
if key not in base_by_key
|
||||
or dict(base_by_key[key].get("parameters") or {})
|
||||
!= dict(item.get("parameters") or {})
|
||||
)
|
||||
merged: list[dict[str, Any]] = []
|
||||
for operation in base_operations:
|
||||
key = (
|
||||
@@ -4397,7 +4413,7 @@ class SeatDemoService:
|
||||
merged.append(deepcopy(change_by_key.pop(key, operation)))
|
||||
merged.extend(deepcopy(list(change_by_key.values())))
|
||||
|
||||
return self._process_mode_profile_create(
|
||||
revised_result = self._process_mode_profile_create(
|
||||
utterance,
|
||||
"local",
|
||||
conversation_id,
|
||||
@@ -4410,6 +4426,26 @@ class SeatDemoService:
|
||||
assistant_plan=self._mode_profile_draft_plan(merged),
|
||||
source_draft=source_draft,
|
||||
)
|
||||
revised_draft = revised_result.get("mode_profile_draft")
|
||||
if (
|
||||
revised_result.get("status") == "succeeded"
|
||||
and isinstance(revised_draft, dict)
|
||||
and revised_draft.get("generation_source") == "draft_revision"
|
||||
):
|
||||
revised_draft["requested_operation_count"] = (
|
||||
requested_operation_count
|
||||
)
|
||||
revised_draft["changed_operation_count"] = changed_operation_count
|
||||
mode_creation = revised_result.get("mode_creation")
|
||||
if isinstance(mode_creation, dict):
|
||||
mode_creation["requested_operation_count"] = (
|
||||
requested_operation_count
|
||||
)
|
||||
mode_creation["changed_operation_count"] = (
|
||||
changed_operation_count
|
||||
)
|
||||
self._persist(revised_result)
|
||||
return revised_result
|
||||
except ValueError as exc:
|
||||
result["status"] = "needs_confirmation"
|
||||
result["execution_mode"] = "dry_run"
|
||||
@@ -7180,7 +7216,21 @@ class SeatDemoService:
|
||||
allow_scene_composition: bool = False,
|
||||
) -> tuple[dict[str, Any], str, str | None]:
|
||||
vehicle_profile = vehicle_profile or self.vehicle_profiles.default()
|
||||
clause_results = self._local_clause_results(utterance, context)
|
||||
if assistant_plan is not None and allow_scene_composition:
|
||||
# ``utterance`` is a synthesized ``进入<mode name>`` carrier for a
|
||||
# name-only scene (and for a server-owned draft revision). Words
|
||||
# inside that label are not user-authored atomic instructions:
|
||||
# e.g. ``外循环通风模式`` previously leaked ``通风`` into the seat
|
||||
# parser and added an AMBIGUOUS_INTENT beside an otherwise valid
|
||||
# climate plan. In this narrow path the complete assistant plan is
|
||||
# the candidate source of actions; it still passes the scene
|
||||
# allowlist, registered capability contract, ModelPlanAdapter,
|
||||
# schema/safety validation and native compiler below.
|
||||
clause_results = [
|
||||
(utterance, self._merge_parsed_results([]), "unparsed")
|
||||
]
|
||||
else:
|
||||
clause_results = self._local_clause_results(utterance, context)
|
||||
|
||||
trusted_local = self._merge_parsed_results(
|
||||
[parsed for _, parsed, status in clause_results if status != "unparsed"]
|
||||
|
||||
Reference in New Issue
Block a user