# coding: utf-8 """ goose-server An AI agent The version of the OpenAPI document: 1.9.0 Contact: ai-oss-tools@block.xyz Generated by OpenAPI Generator (https://openapi-generator.tech) Do not edit the class manually. """ # noqa: E501 from __future__ import annotations import pprint import re # noqa: F401 import json from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated from goose_api.models.success_check import SuccessCheck from typing import Optional, Set from typing_extensions import Self class RetryConfig(BaseModel): """ Configuration for retry logic in recipe execution """ # noqa: E501 checks: List[SuccessCheck] = Field(description="List of success checks to validate recipe completion") max_retries: Annotated[int, Field(strict=True, ge=0)] = Field(description="Maximum number of retry attempts before giving up") on_failure: Optional[StrictStr] = Field(default=None, description="Optional shell command to run on failure for cleanup") on_failure_timeout_seconds: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, description="Timeout in seconds for on_failure commands (default: 600 seconds)") timeout_seconds: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, description="Timeout in seconds for individual shell commands (default: 300 seconds)") __properties: ClassVar[List[str]] = ["checks", "max_retries", "on_failure", "on_failure_timeout_seconds", "timeout_seconds"] model_config = ConfigDict( populate_by_name=True, validate_assignment=True, protected_namespaces=(), ) def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead return json.dumps(self.to_dict()) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: """Create an instance of RetryConfig from a JSON string""" return cls.from_dict(json.loads(json_str)) def to_dict(self) -> Dict[str, Any]: """Return the dictionary representation of the model using alias. This has the following differences from calling pydantic's `self.model_dump(by_alias=True)`: * `None` is only added to the output dict for nullable fields that were set at model initialization. Other fields with value `None` are ignored. """ excluded_fields: Set[str] = set([ ]) _dict = self.model_dump( by_alias=True, exclude=excluded_fields, exclude_none=True, ) # override the default output from pydantic by calling `to_dict()` of each item in checks (list) _items = [] if self.checks: for _item_checks in self.checks: if _item_checks: _items.append(_item_checks.to_dict()) _dict['checks'] = _items # set to None if on_failure (nullable) is None # and model_fields_set contains the field if self.on_failure is None and "on_failure" in self.model_fields_set: _dict['on_failure'] = None # set to None if on_failure_timeout_seconds (nullable) is None # and model_fields_set contains the field if self.on_failure_timeout_seconds is None and "on_failure_timeout_seconds" in self.model_fields_set: _dict['on_failure_timeout_seconds'] = None # set to None if timeout_seconds (nullable) is None # and model_fields_set contains the field if self.timeout_seconds is None and "timeout_seconds" in self.model_fields_set: _dict['timeout_seconds'] = None return _dict @classmethod def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: """Create an instance of RetryConfig from a dict""" if obj is None: return None if not isinstance(obj, dict): return cls.model_validate(obj) _obj = cls.model_validate({ "checks": [SuccessCheck.from_dict(_item) for _item in obj["checks"]] if obj.get("checks") is not None else None, "max_retries": obj.get("max_retries"), "on_failure": obj.get("on_failure"), "on_failure_timeout_seconds": obj.get("on_failure_timeout_seconds"), "timeout_seconds": obj.get("timeout_seconds") }) return _obj