diff --git a/app/src/ai/cloud_environments/mod.rs b/app/src/ai/cloud_environments/mod.rs index 78964d0290..9410e7f6fa 100644 --- a/app/src/ai/cloud_environments/mod.rs +++ b/app/src/ai/cloud_environments/mod.rs @@ -1,5 +1,7 @@ -use serde::{Deserialize, Serialize}; -use std::fmt; +pub use warp_server_client::cloud_object::models::{ + AmbientAgentEnvironment, AwsProviderConfig, BaseImage, GcpProviderConfig, GithubRepo, + ProvidersConfig, +}; use warp_server_client::cloud_object::Owner; use crate::{ @@ -17,117 +19,11 @@ use crate::{ }; use warpui::{AppContext, SingletonEntity as _}; -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -pub struct GithubRepo { - /// Repository owner (e.g. "warpdotdev") - pub owner: String, - /// Repository name (e.g. "warp-internal") - pub repo: String, -} - -impl GithubRepo { - pub fn new(owner: String, repo: String) -> Self { - Self { owner, repo } - } -} - -impl fmt::Display for GithubRepo { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}/{}", self.owner, self.repo) - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "snake_case")] -pub enum BaseImage { - DockerImage(String), -} - -impl fmt::Display for BaseImage { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - BaseImage::DockerImage(s) => s.fmt(f), - } - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct GcpProviderConfig { - pub project_number: String, - pub workload_identity_federation_pool_id: String, - pub workload_identity_federation_provider_id: String, - /// Service account email for impersonation. When set, the federated token - /// is exchanged for a service account access token. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub service_account_email: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct AwsProviderConfig { - pub role_arn: String, -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)] -pub struct ProvidersConfig { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub gcp: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub aws: Option, -} - -impl ProvidersConfig { - pub fn is_empty(&self) -> bool { - self.gcp.is_none() && self.aws.is_none() - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -/// An AmbientAgentEnvironment represents an environment that we would run a Warp agent in. -pub struct AmbientAgentEnvironment { - /// Environment name - #[serde(default)] - pub name: String, - /// Optional description of the environment (max 240 characters) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub description: Option, - /// List of GitHub repositories - #[serde(default)] - pub github_repos: Vec, - /// Base image specification - #[serde(flatten)] - pub base_image: BaseImage, - /// List of setup commands to run after cloning - #[serde(default)] - pub setup_commands: Vec, - /// Optional cloud provider configurations for automatic auth. - #[serde(default, skip_serializing_if = "ProvidersConfig::is_empty")] - pub providers: ProvidersConfig, -} - pub type CloudAmbientAgentEnvironment = GenericCloudObject; pub type CloudAmbientAgentEnvironmentModel = GenericStringModel; -impl AmbientAgentEnvironment { - pub fn new( - name: String, - description: Option, - github_repos: Vec, - docker_image: String, - setup_commands: Vec, - ) -> Self { - Self { - name, - description, - github_repos, - base_image: BaseImage::DockerImage(docker_image), - setup_commands, - providers: ProvidersConfig::default(), - } - } -} - impl StringModel for AmbientAgentEnvironment { type CloudObjectType = CloudAmbientAgentEnvironment; diff --git a/app/src/workflows/workflow_enum.rs b/app/src/workflows/workflow_enum.rs index 5dbce3cb1d..a020485eec 100644 --- a/app/src/workflows/workflow_enum.rs +++ b/app/src/workflows/workflow_enum.rs @@ -1,4 +1,4 @@ -use serde::{Deserialize, Serialize}; +pub use warp_server_client::cloud_object::models::{EnumVariants, WorkflowEnum}; use crate::{ cloud_object::{ @@ -12,27 +12,6 @@ use crate::{ server::sync_queue::QueueItem, }; -/// Data model for a workflow enum, one type of argument that can be inserted into a workflow -/// A workflow enum can either be static or dynamic, as determined by the type of `EnumVariants` it uses -/// -/// A `Static` enum contains a finite set of user-specified string values -/// A `Dynamic` enum contains a single shell command, which is executed to determine suggested variants for that argument -#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, Hash, PartialOrd)] -pub struct WorkflowEnum { - /// Enum name - pub name: String, - /// Whether or not the variable should be visible to other workflows - pub is_shared: bool, - /// The variants for this enum - pub variants: EnumVariants, -} - -#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, Hash, PartialOrd)] -pub enum EnumVariants { - Static(Vec), // contains the explicit variants for a static enum - Dynamic(String), // contains the value of the shell command associated with the dynamic enum -} - pub type CloudWorkflowEnum = GenericCloudObject; pub type CloudWorkflowEnumModel = GenericStringModel; diff --git a/crates/warp_server_client/src/cloud_object/mod.rs b/crates/warp_server_client/src/cloud_object/mod.rs index ec362816f0..523aa01d6a 100644 --- a/crates/warp_server_client/src/cloud_object/mod.rs +++ b/crates/warp_server_client/src/cloud_object/mod.rs @@ -28,6 +28,7 @@ use crate::{ mod creation; mod generic_cloud_object; mod generic_string_model; +pub mod models; mod server_object; mod update; diff --git a/crates/warp_server_client/src/cloud_object/models/cloud_environment.rs b/crates/warp_server_client/src/cloud_object/models/cloud_environment.rs new file mode 100644 index 0000000000..1d0b51dee1 --- /dev/null +++ b/crates/warp_server_client/src/cloud_object/models/cloud_environment.rs @@ -0,0 +1,109 @@ +use std::fmt; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct GithubRepo { + /// Repository owner, for example "warpdotdev". + pub owner: String, + /// Repository name, for example "warp-internal". + pub repo: String, +} + +impl GithubRepo { + pub fn new(owner: String, repo: String) -> Self { + Self { owner, repo } + } +} + +impl fmt::Display for GithubRepo { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}/{}", self.owner, self.repo) + } +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum BaseImage { + DockerImage(String), +} + +impl fmt::Display for BaseImage { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + BaseImage::DockerImage(s) => s.fmt(f), + } + } +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct GcpProviderConfig { + pub project_number: String, + pub workload_identity_federation_pool_id: String, + pub workload_identity_federation_provider_id: String, + /// Service account email for impersonation. When set, the federated token + /// is exchanged for a service account access token. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub service_account_email: Option, +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct AwsProviderConfig { + pub role_arn: String, +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)] +pub struct ProvidersConfig { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub gcp: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub aws: Option, +} + +impl ProvidersConfig { + pub fn is_empty(&self) -> bool { + self.gcp.is_none() && self.aws.is_none() + } +} + +/// An AmbientAgentEnvironment represents an environment that we would run a Warp agent in. +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct AmbientAgentEnvironment { + /// Environment name. + #[serde(default)] + pub name: String, + /// Optional description of the environment, up to 240 characters. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub description: Option, + /// List of GitHub repositories. + #[serde(default)] + pub github_repos: Vec, + /// Base image specification. + #[serde(flatten)] + pub base_image: BaseImage, + /// List of setup commands to run after cloning. + #[serde(default)] + pub setup_commands: Vec, + /// Optional cloud provider configurations for automatic auth. + #[serde(default, skip_serializing_if = "ProvidersConfig::is_empty")] + pub providers: ProvidersConfig, +} + +impl AmbientAgentEnvironment { + pub fn new( + name: String, + description: Option, + github_repos: Vec, + docker_image: String, + setup_commands: Vec, + ) -> Self { + Self { + name, + description, + github_repos, + base_image: BaseImage::DockerImage(docker_image), + setup_commands, + providers: ProvidersConfig::default(), + } + } +} diff --git a/crates/warp_server_client/src/cloud_object/models/mod.rs b/crates/warp_server_client/src/cloud_object/models/mod.rs new file mode 100644 index 0000000000..dad9cfde05 --- /dev/null +++ b/crates/warp_server_client/src/cloud_object/models/mod.rs @@ -0,0 +1,5 @@ +mod cloud_environment; +mod workflow_enum; + +pub use cloud_environment::*; +pub use workflow_enum::*; diff --git a/crates/warp_server_client/src/cloud_object/models/workflow_enum.rs b/crates/warp_server_client/src/cloud_object/models/workflow_enum.rs new file mode 100644 index 0000000000..b3590e9a00 --- /dev/null +++ b/crates/warp_server_client/src/cloud_object/models/workflow_enum.rs @@ -0,0 +1,24 @@ +use serde::{Deserialize, Serialize}; + +/// Data model for a workflow enum, one type of argument that can be inserted into a workflow. +/// A workflow enum can either be static or dynamic, as determined by the type of `EnumVariants` it uses. +/// +/// A `Static` enum contains a finite set of user-specified string values. +/// A `Dynamic` enum contains a single shell command, which is executed to determine suggested variants for that argument. +#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, Hash, PartialOrd)] +pub struct WorkflowEnum { + /// The enum name. + pub name: String, + /// Whether or not the variable should be visible to other workflows. + pub is_shared: bool, + /// The variants for this enum. + pub variants: EnumVariants, +} + +#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, Hash, PartialOrd)] +pub enum EnumVariants { + /// Contains the explicit variants for a static enum. + Static(Vec), + /// Contains the value of the shell command associated with the dynamic enum. + Dynamic(String), +}