From d14fff2d6dc6df872f41cadb2b0092c6e5097f58 Mon Sep 17 00:00:00 2001 From: David Stern Date: Sat, 16 May 2026 17:55:59 -0400 Subject: [PATCH] Move `WorkflowEnum` model to `warp_server_client`. --- app/src/ai/cloud_environments/mod.rs | 127 ++---------------- app/src/workflows/workflow_enum.rs | 23 +--- .../src/cloud_object/mod.rs | 1 + .../cloud_object/models/cloud_environment.rs | 109 +++++++++++++++ .../src/cloud_object/models/mod.rs | 5 + .../src/cloud_object/models/workflow_enum.rs | 22 +++ 6 files changed, 148 insertions(+), 139 deletions(-) create mode 100644 crates/warp_server_client/src/cloud_object/models/cloud_environment.rs create mode 100644 crates/warp_server_client/src/cloud_object/models/mod.rs create mode 100644 crates/warp_server_client/src/cloud_object/models/workflow_enum.rs diff --git a/app/src/ai/cloud_environments/mod.rs b/app/src/ai/cloud_environments/mod.rs index e1fc6ee572..80bcf0e235 100644 --- a/app/src/ai/cloud_environments/mod.rs +++ b/app/src/ai/cloud_environments/mod.rs @@ -1,132 +1,25 @@ -use std::fmt; - -use serde::{Deserialize, Serialize}; -use warp_server_client::cloud_object::Owner; +pub use warp_server_client::cloud_object::models::{ + AmbientAgentEnvironment, AwsProviderConfig, BaseImage, GcpProviderConfig, GithubRepo, + ProvidersConfig, +}; +use warp_server_client::cloud_object::{ + GenericCloudObject, GenericStringModel, GenericStringObjectFormat, + GenericStringObjectUniqueKey, JsonObjectType, Owner, Revision, +}; +use warp_server_client::ids::GenericStringObjectId; use warpui::{AppContext, SingletonEntity as _}; use crate::auth::AuthStateProvider; -use crate::cloud_object::model::generic_string_model::{ - GenericStringModel, GenericStringObjectId, StringModel, -}; +use crate::cloud_object::model::generic_string_model::StringModel; use crate::cloud_object::model::json_model::{JsonModel, JsonSerializer}; -use crate::cloud_object::{ - GenericCloudObject, GenericStringObjectFormat, GenericStringObjectUniqueKey, JsonObjectType, - Revision, -}; use crate::server::sync_queue::QueueItem; use crate::workspaces::user_workspaces::UserWorkspaces; -#[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 9ed954566e..668d2651e5 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::model::generic_string_model::{ GenericStringModel, GenericStringObjectId, StringModel, @@ -10,27 +10,6 @@ use crate::cloud_object::{ }; 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 50d70bbaff..9a026ce670 100644 --- a/crates/warp_server_client/src/cloud_object/mod.rs +++ b/crates/warp_server_client/src/cloud_object/mod.rs @@ -27,6 +27,7 @@ use crate::ids::{FolderId, ServerId, SyncId}; 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..689e9773d6 --- /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 (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() + } +} + +/// 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 (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, +} + +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..fd3743689b --- /dev/null +++ b/crates/warp_server_client/src/cloud_object/models/workflow_enum.rs @@ -0,0 +1,22 @@ +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 { + /// 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 +}