MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / LoopTimerConfig

Class LoopTimerConfig

entity/configs/node/loop_timer.py:18–133  ·  view source on GitHub ↗

Configuration schema for the loop timer node type.

Source from the content-addressed store, hash-verified

16
17@dataclass
18class LoopTimerConfig(BaseConfig):
19 """Configuration schema for the loop timer node type."""
20
21 max_duration: float = 60.0
22 duration_unit: str = "seconds"
23 reset_on_emit: bool = True
24 message: Optional[str] = None
25 passthrough: bool = False
26
27 @classmethod
28 def from_dict(
29 cls, data: Mapping[str, Any] | None, *, path: str
30 ) -> "LoopTimerConfig":
31 mapping = require_mapping(data or {}, path)
32 max_duration_raw = mapping.get("max_duration", 60.0)
33 try:
34 max_duration = float(max_duration_raw)
35 except (TypeError, ValueError) as exc: # pragma: no cover - defensive
36 raise ConfigError(
37 "max_duration must be a number",
38 extend_path(path, "max_duration"),
39 ) from exc
40
41 if max_duration <= 0:
42 raise ConfigError(
43 "max_duration must be > 0", extend_path(path, "max_duration")
44 )
45
46 duration_unit = str(mapping.get("duration_unit", "seconds"))
47 valid_units = ["seconds", "minutes", "hours"]
48 if duration_unit not in valid_units:
49 raise ConfigError(
50 f"duration_unit must be one of: {', '.join(valid_units)}",
51 extend_path(path, "duration_unit"),
52 )
53
54 reset_on_emit = bool(mapping.get("reset_on_emit", True))
55 message = optional_str(mapping, "message", path)
56 passthrough = bool(mapping.get("passthrough", False))
57
58 return cls(
59 max_duration=max_duration,
60 duration_unit=duration_unit,
61 reset_on_emit=reset_on_emit,
62 message=message,
63 passthrough=passthrough,
64 path=path,
65 )
66
67 def validate(self) -> None:
68 if self.max_duration <= 0:
69 raise ConfigError(
70 "max_duration must be > 0", extend_path(self.path, "max_duration")
71 )
72
73 valid_units = ["seconds", "minutes", "hours"]
74 if self.duration_unit not in valid_units:
75 raise ConfigError(

Callers

nothing calls this directly

Calls 2

ConfigFieldSpecClass · 0.90
EnumOptionClass · 0.90

Tested by

no test coverage detected