OUTPUT #1138 | 1432 karakter | 22 satır
           transport: Optional[client.Transport] = None) -> Dict[str, Any]:
    """Raises ValueError for a bad request. A Jev failure returns ``reobserve``, never a guess."""
    valid = validate(request)
    table = valid["table"]

    def answer(selected: str, confidence: float, reason: str, probabilities: Optional[Dict[str, float]] = None) -> Dict[str, Any]:
        return {"schema": RESPONSE_SCHEMA, "selected_id": selected, "confidence": round(confidence, 3), "reason": reason,
                "observation_id": valid["observation_id"], "probabilities": probabilities or {}}

    if mock:
        return answer("reobserve", 1.0, "mock")
    state = {"goal": valid["goal"], "on_screen": valid["regions"], "already_tried": valid["history"]}
    question = client.choice("Which single action should be taken next to move toward the goal?", table)
    try:
        reply = client.ask(state, {"next_action": question}, timeout=timeout, transport=transport)
    except client.JevError as error:
        return answer("reobserve", 0.0, f"Jev unavailable ({error.code})")
    picked = reply["answers"]["next_action"]
    if picked["confidence"] < MIN_CONFIDENCE:
        return answer("reobserve", picked["confidence"], "low confidence", picked["probabilities"])
    return answer(picked["choice"], picked["confidence"], "chosen", picked["probabilities"])
root@213-238-170-219:/home/hermes/jev-community-review#