File size: 2,707 Bytes
ae94737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from __future__ import annotations

from typing import Any

from pydantic import BaseModel, Field


class Observation(BaseModel):
    task_id: str
    difficulty: str
    failure_stage: str
    actual_bug: str
    config: str
    logs: str
    error_message: str
    available_tools: list[str]
    progress_flags: dict[str, bool]
    file_modification_count: int
    hidden_test_pass_rate: float
    step_count: int
    last_action_error: str | None = None


class Action(BaseModel):
    tool: str = ""
    payload: dict[str, Any] = Field(default_factory=dict)

    @classmethod
    def from_input(cls, raw_action: Any) -> "Action":
        if isinstance(raw_action, cls):
            return raw_action

        if isinstance(raw_action, str):
            raw = raw_action.strip()
            if not raw:
                return cls(tool="", payload={})

            if ":" in raw:
                tool_part, payload_part = raw.split(":", 1)
                return cls(tool=tool_part.strip().lower(), payload={"raw": payload_part.strip()})

            parts = raw.split(maxsplit=1)
            tool = parts[0].strip().lower() if parts else ""
            payload = {"raw": parts[1].strip()} if len(parts) > 1 else {}
            return cls(tool=tool, payload=payload)

        if isinstance(raw_action, dict):
            tool = str(raw_action.get("tool") or raw_action.get("action_type") or "").strip().lower()
            incoming_payload = raw_action.get("payload")

            if isinstance(incoming_payload, dict):
                payload: dict[str, Any] = dict(incoming_payload)
            elif incoming_payload is not None:
                payload = {"raw": str(incoming_payload)}
            elif "input" in raw_action:
                payload = {"raw": str(raw_action.get("input") or "").strip()}
            else:
                payload = {}

            return cls(tool=tool, payload=payload)

        return cls(tool="", payload={})


class Reward(BaseModel):
    value: float = Field(ge=0.0, le=1.0)
    components: dict[str, float] = Field(default_factory=dict)


class EnvStateSnapshot(BaseModel):
    initialized: bool
    task_id: str | None = None
    difficulty: str | None = None
    actual_bug: str | None = None
    correct_solution: str | None = None
    failure_stage: str | None = None
    step_count: int = 0
    done: bool = False
    progress_flags: dict[str, bool] = Field(default_factory=dict)
    file_modification_count: int = 0
    total_changed_lines: int = 0
    hidden_test_pass_rate: float = 0.0
    stage_results: dict[str, bool] = Field(default_factory=dict)
    failed_validations: int = 0
    last_action_error: str | None = None
    last_error: str | None = None