Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 4 additions & 108 deletions app/src/ai/cloud_environments/mod.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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<String>,
}

#[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<GcpProviderConfig>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub aws: Option<AwsProviderConfig>,
}

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<String>,
/// List of GitHub repositories
#[serde(default)]
pub github_repos: Vec<GithubRepo>,
/// Base image specification
#[serde(flatten)]
pub base_image: BaseImage,
/// List of setup commands to run after cloning
#[serde(default)]
pub setup_commands: Vec<String>,
/// Optional cloud provider configurations for automatic auth.
#[serde(default, skip_serializing_if = "ProvidersConfig::is_empty")]
pub providers: ProvidersConfig,
}

pub type CloudAmbientAgentEnvironment =
GenericCloudObject<GenericStringObjectId, CloudAmbientAgentEnvironmentModel>;
pub type CloudAmbientAgentEnvironmentModel =
GenericStringModel<AmbientAgentEnvironment, JsonSerializer>;

impl AmbientAgentEnvironment {
pub fn new(
name: String,
description: Option<String>,
github_repos: Vec<GithubRepo>,
docker_image: String,
setup_commands: Vec<String>,
) -> Self {
Self {
name,
description,
github_repos,
base_image: BaseImage::DockerImage(docker_image),
setup_commands,
providers: ProvidersConfig::default(),
}
}
}

impl StringModel for AmbientAgentEnvironment {
type CloudObjectType = CloudAmbientAgentEnvironment;

Expand Down
23 changes: 1 addition & 22 deletions app/src/workflows/workflow_enum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Deserialize, Serialize};
pub use warp_server_client::cloud_object::models::{EnumVariants, WorkflowEnum};

use crate::{
cloud_object::{
Expand All @@ -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<String>), // 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<GenericStringObjectId, CloudWorkflowEnumModel>;
pub type CloudWorkflowEnumModel = GenericStringModel<WorkflowEnum, JsonSerializer>;

Expand Down
1 change: 1 addition & 0 deletions crates/warp_server_client/src/cloud_object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
mod creation;
mod generic_cloud_object;
mod generic_string_model;
pub mod models;
mod server_object;
mod update;

Expand Down
109 changes: 109 additions & 0 deletions crates/warp_server_client/src/cloud_object/models/cloud_environment.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}

#[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<GcpProviderConfig>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub aws: Option<AwsProviderConfig>,
}

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<String>,
/// List of GitHub repositories.
#[serde(default)]
pub github_repos: Vec<GithubRepo>,
/// Base image specification.
#[serde(flatten)]
pub base_image: BaseImage,
/// List of setup commands to run after cloning.
#[serde(default)]
pub setup_commands: Vec<String>,
/// 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<String>,
github_repos: Vec<GithubRepo>,
docker_image: String,
setup_commands: Vec<String>,
) -> Self {
Self {
name,
description,
github_repos,
base_image: BaseImage::DockerImage(docker_image),
setup_commands,
providers: ProvidersConfig::default(),
}
}
}
5 changes: 5 additions & 0 deletions crates/warp_server_client/src/cloud_object/models/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod cloud_environment;
mod workflow_enum;

pub use cloud_environment::*;
pub use workflow_enum::*;
24 changes: 24 additions & 0 deletions crates/warp_server_client/src/cloud_object/models/workflow_enum.rs
Original file line number Diff line number Diff line change
@@ -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<String>),
/// Contains the value of the shell command associated with the dynamic enum.
Dynamic(String),
}