feat(p1): persist workflows and semantic learning artifacts

This commit is contained in:
Dom
2026-06-02 16:20:38 +02:00
parent 7a1a5cb6fd
commit 86b3c8f7e7
21 changed files with 3816 additions and 31 deletions

View File

@@ -701,11 +701,47 @@ def _vwb_params_to_core(action_type: str, params: Dict[str, Any]) -> Dict[str, A
return core_params
def _first_non_empty(*values: Any) -> str:
for value in values:
text = str(value or "").strip()
if text and text.casefold() not in {"none", "null"}:
return text
return ""
def _vwb_params_to_target_spec(action_type: str, params: Dict[str, Any]) -> Dict[str, Any]:
"""Construit un TargetSpec core depuis les paramètres VWB."""
visual_anchor = params.get("visual_anchor") or {}
if not isinstance(visual_anchor, dict):
visual_anchor = {}
target_text = _first_non_empty(
params.get("target_text"),
params.get("by_text"),
visual_anchor.get("target_text"),
)
description = _first_non_empty(
params.get("description"),
visual_anchor.get("description"),
)
ocr_description = _first_non_empty(
params.get("ocr_description"),
visual_anchor.get("ocr_description"),
)
vlm_description = _first_non_empty(
params.get("vlm_description"),
description,
ocr_description,
)
anchor_id = _first_non_empty(
params.get("anchor_id"),
visual_anchor.get("anchor_id"),
visual_anchor.get("id"),
)
target = {
"by_role": params.get("target_role", "unknown_element"),
"by_text": params.get("target_text"),
"by_text": target_text or None,
"by_position": None,
"selection_policy": "first",
"fallback_strategy": "visual_similarity",
@@ -717,6 +753,27 @@ def _vwb_params_to_target_spec(action_type: str, params: Dict[str, Any]) -> Dict
if x_pct is not None and y_pct is not None:
target["by_position"] = [x_pct, y_pct]
context_hints: Dict[str, Any] = {}
if anchor_id:
context_hints["anchor_id"] = anchor_id
if target_text:
context_hints["target_text"] = target_text
context_hints["by_text_source"] = "visual_anchor"
if description:
context_hints["description"] = description
if ocr_description:
context_hints["ocr_description"] = ocr_description
if vlm_description:
context_hints["vlm_description"] = vlm_description
if visual_anchor.get("anchor_bbox") or visual_anchor.get("bounding_box"):
context_hints["anchor_bbox"] = (
visual_anchor.get("anchor_bbox") or visual_anchor.get("bounding_box")
)
if visual_anchor.get("original_size"):
context_hints["original_size"] = visual_anchor["original_size"]
if context_hints:
target["context_hints"] = context_hints
return target