1010from typing_extensions import Self
1111
1212from dstack ._internal .core .errors import ConfigurationError
13- from dstack ._internal .core .models .common import CoreModel , Duration , RegistryAuth
13+ from dstack ._internal .core .models .common import (
14+ CoreConfig ,
15+ CoreModel ,
16+ Duration ,
17+ RegistryAuth ,
18+ generate_dual_core_model ,
19+ )
1420from dstack ._internal .core .models .envs import Env
1521from dstack ._internal .core .models .files import FilePathMapping
1622from dstack ._internal .core .models .fleets import FleetConfiguration
1723from dstack ._internal .core .models .gateways import GatewayConfiguration
18- from dstack ._internal .core .models .profiles import ProfileParams , parse_duration , parse_off_duration
24+ from dstack ._internal .core .models .profiles import (
25+ ProfileParams ,
26+ ProfileParamsConfig ,
27+ parse_duration ,
28+ parse_off_duration ,
29+ )
1930from dstack ._internal .core .models .resources import Range , ResourcesSpec
2031from dstack ._internal .core .models .services import AnyModel , OpenAIChatModel
2132from dstack ._internal .core .models .unix import UnixUser
@@ -276,7 +287,20 @@ class HTTPHeaderSpec(CoreModel):
276287 ]
277288
278289
279- class ProbeConfig (CoreModel ):
290+ class ProbeConfigConfig (CoreConfig ):
291+ @staticmethod
292+ def schema_extra (schema : Dict [str , Any ]):
293+ add_extra_schema_types (
294+ schema ["properties" ]["timeout" ],
295+ extra_types = [{"type" : "string" }],
296+ )
297+ add_extra_schema_types (
298+ schema ["properties" ]["interval" ],
299+ extra_types = [{"type" : "string" }],
300+ )
301+
302+
303+ class ProbeConfig (generate_dual_core_model (ProbeConfigConfig )):
280304 type : Literal ["http" ] # expect other probe types in the future, namely `exec`
281305 url : Annotated [
282306 Optional [str ], Field (description = f"The URL to request. Defaults to `{ DEFAULT_PROBE_URL } `" )
@@ -331,18 +355,6 @@ class ProbeConfig(CoreModel):
331355 ),
332356 ] = None
333357
334- class Config (CoreModel .Config ):
335- @staticmethod
336- def schema_extra (schema : Dict [str , Any ]):
337- add_extra_schema_types (
338- schema ["properties" ]["timeout" ],
339- extra_types = [{"type" : "string" }],
340- )
341- add_extra_schema_types (
342- schema ["properties" ]["interval" ],
343- extra_types = [{"type" : "string" }],
344- )
345-
346358 @validator ("timeout" , pre = True )
347359 def parse_timeout (cls , v : Optional [Union [int , str ]]) -> Optional [int ]:
348360 if v is None :
@@ -381,6 +393,19 @@ def validate_body_matches_method(cls, values):
381393 return values
382394
383395
396+ class BaseRunConfigurationConfig (CoreConfig ):
397+ @staticmethod
398+ def schema_extra (schema : Dict [str , Any ]):
399+ add_extra_schema_types (
400+ schema ["properties" ]["volumes" ]["items" ],
401+ extra_types = [{"type" : "string" }],
402+ )
403+ add_extra_schema_types (
404+ schema ["properties" ]["files" ]["items" ],
405+ extra_types = [{"type" : "string" }],
406+ )
407+
408+
384409class BaseRunConfiguration (CoreModel ):
385410 type : Literal ["none" ]
386411 name : Annotated [
@@ -484,18 +509,6 @@ class BaseRunConfiguration(CoreModel):
484509 # deprecated since 0.18.31; task, service -- no effect; dev-environment -- executed right before `init`
485510 setup : CommandsList = []
486511
487- class Config (CoreModel .Config ):
488- @staticmethod
489- def schema_extra (schema : Dict [str , Any ]):
490- add_extra_schema_types (
491- schema ["properties" ]["volumes" ]["items" ],
492- extra_types = [{"type" : "string" }],
493- )
494- add_extra_schema_types (
495- schema ["properties" ]["files" ]["items" ],
496- extra_types = [{"type" : "string" }],
497- )
498-
499512 @validator ("python" , pre = True , always = True )
500513 def convert_python (cls , v , values ) -> Optional [PythonVersion ]:
501514 if v is not None and values .get ("image" ):
@@ -621,20 +634,25 @@ def parse_inactivity_duration(
621634 return None
622635
623636
637+ class DevEnvironmentConfigurationConfig (
638+ ProfileParamsConfig ,
639+ BaseRunConfigurationConfig ,
640+ ):
641+ @staticmethod
642+ def schema_extra (schema : Dict [str , Any ]):
643+ ProfileParamsConfig .schema_extra (schema )
644+ BaseRunConfigurationConfig .schema_extra (schema )
645+
646+
624647class DevEnvironmentConfiguration (
625648 ProfileParams ,
626649 BaseRunConfiguration ,
627650 ConfigurationWithPortsParams ,
628651 DevEnvironmentConfigurationParams ,
652+ generate_dual_core_model (DevEnvironmentConfigurationConfig ),
629653):
630654 type : Literal ["dev-environment" ] = "dev-environment"
631655
632- class Config (ProfileParams .Config , BaseRunConfiguration .Config ):
633- @staticmethod
634- def schema_extra (schema : Dict [str , Any ]):
635- ProfileParams .Config .schema_extra (schema )
636- BaseRunConfiguration .Config .schema_extra (schema )
637-
638656 @validator ("entrypoint" )
639657 def validate_entrypoint (cls , v : Optional [str ]) -> Optional [str ]:
640658 if v is not None :
@@ -646,20 +664,38 @@ class TaskConfigurationParams(CoreModel):
646664 nodes : Annotated [int , Field (description = "Number of nodes" , ge = 1 )] = 1
647665
648666
667+ class TaskConfigurationConfig (
668+ ProfileParamsConfig ,
669+ BaseRunConfigurationConfig ,
670+ ):
671+ @staticmethod
672+ def schema_extra (schema : Dict [str , Any ]):
673+ ProfileParamsConfig .schema_extra (schema )
674+ BaseRunConfigurationConfig .schema_extra (schema )
675+
676+
649677class TaskConfiguration (
650678 ProfileParams ,
651679 BaseRunConfiguration ,
652680 ConfigurationWithCommandsParams ,
653681 ConfigurationWithPortsParams ,
654682 TaskConfigurationParams ,
683+ generate_dual_core_model (TaskConfigurationConfig ),
655684):
656685 type : Literal ["task" ] = "task"
657686
658- class Config (ProfileParams .Config , BaseRunConfiguration .Config ):
659- @staticmethod
660- def schema_extra (schema : Dict [str , Any ]):
661- ProfileParams .Config .schema_extra (schema )
662- BaseRunConfiguration .Config .schema_extra (schema )
687+
688+ class ServiceConfigurationParamsConfig (CoreConfig ):
689+ @staticmethod
690+ def schema_extra (schema : Dict [str , Any ]):
691+ add_extra_schema_types (
692+ schema ["properties" ]["replicas" ],
693+ extra_types = [{"type" : "integer" }, {"type" : "string" }],
694+ )
695+ add_extra_schema_types (
696+ schema ["properties" ]["model" ],
697+ extra_types = [{"type" : "string" }],
698+ )
663699
664700
665701class ServiceConfigurationParams (CoreModel ):
@@ -719,18 +755,6 @@ class ServiceConfigurationParams(CoreModel):
719755 Field (description = "List of probes used to determine job health" ),
720756 ] = []
721757
722- class Config (CoreModel .Config ):
723- @staticmethod
724- def schema_extra (schema : Dict [str , Any ]):
725- add_extra_schema_types (
726- schema ["properties" ]["replicas" ],
727- extra_types = [{"type" : "integer" }, {"type" : "string" }],
728- )
729- add_extra_schema_types (
730- schema ["properties" ]["model" ],
731- extra_types = [{"type" : "string" }],
732- )
733-
734758 @validator ("port" )
735759 def convert_port (cls , v ) -> PortMapping :
736760 if isinstance (v , int ):
@@ -797,25 +821,27 @@ def validate_probes(cls, v: list[ProbeConfig]) -> list[ProbeConfig]:
797821 return v
798822
799823
824+ class ServiceConfigurationConfig (
825+ ProfileParamsConfig ,
826+ BaseRunConfigurationConfig ,
827+ ServiceConfigurationParamsConfig ,
828+ ):
829+ @staticmethod
830+ def schema_extra (schema : Dict [str , Any ]):
831+ ProfileParamsConfig .schema_extra (schema )
832+ BaseRunConfigurationConfig .schema_extra (schema )
833+ ServiceConfigurationParamsConfig .schema_extra (schema )
834+
835+
800836class ServiceConfiguration (
801837 ProfileParams ,
802838 BaseRunConfiguration ,
803839 ConfigurationWithCommandsParams ,
804840 ServiceConfigurationParams ,
841+ generate_dual_core_model (ServiceConfigurationConfig ),
805842):
806843 type : Literal ["service" ] = "service"
807844
808- class Config (
809- ProfileParams .Config ,
810- BaseRunConfiguration .Config ,
811- ServiceConfigurationParams .Config ,
812- ):
813- @staticmethod
814- def schema_extra (schema : Dict [str , Any ]):
815- ProfileParams .Config .schema_extra (schema )
816- BaseRunConfiguration .Config .schema_extra (schema )
817- ServiceConfigurationParams .Config .schema_extra (schema )
818-
819845
820846AnyRunConfiguration = Union [DevEnvironmentConfiguration , TaskConfiguration , ServiceConfiguration ]
821847
@@ -876,7 +902,7 @@ class DstackConfiguration(CoreModel):
876902 Field (discriminator = "type" ),
877903 ]
878904
879- class Config (CoreModel . Config ):
905+ class Config (CoreConfig ):
880906 json_loads = orjson .loads
881907 json_dumps = pydantic_orjson_dumps_with_indent
882908
0 commit comments