use serde::{Deserialize, Serialize};
use serde_json::{json, Map, Value};
use super::Result;
pub const DEFAULT_PLATFORM_API_URL: &str = "https://platform.marona.ai/api";
#[derive(Clone)]
pub struct DeveloperHubClient {
hub_url: String,
token: String,
client: reqwest::Client,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct HostedDeploymentRequest {
pub source_type: String,
pub source_url: Option<String>,
pub version: Option<String>,
pub branch: Option<String>,
pub entrypoint: Option<String>,
#[serde(default = "rust_runtime")]
pub runtime: String,
pub provider: Option<String>,
pub region: Option<String>,
pub cluster_id: Option<String>,
#[serde(default)]
pub environment: Map<String, Value>,
#[serde(default)]
pub secrets: Map<String, Value>,
#[serde(default)]
pub runtime_config: Map<String, Value>,
}
impl DeveloperHubClient {
pub fn for_platform(token: impl Into<String>) -> Result<Self> {
Self::new(DEFAULT_PLATFORM_API_URL, token)
}
pub fn new(hub_url: impl Into<String>, token: impl Into<String>) -> Result<Self> {
let token = token.into();
if token.trim().is_empty() {
return Err(super::Error::Configuration("Hub token is required".into()));
}
Ok(Self {
hub_url: hub_url.into().trim_end_matches('/').into(),
token,
client: reqwest::Client::new(),
})
}
pub async fn create_agent_app(&self, payload: Value) -> Result<Value> {
self.request(
reqwest::Method::POST,
"/portal/developer/agent-apps",
Some(payload),
)
.await
}
pub async fn sync_agent_app(&self, app_id: &str) -> Result<Value> {
self.request(
reqwest::Method::POST,
&format!("/portal/developer/agent-apps/{app_id}/sync-mcp-server"),
None,
)
.await
}
pub async fn submit_agent_app(&self, app_id: &str, comments: Option<&str>) -> Result<Value> {
self.request(
reqwest::Method::POST,
&format!("/portal/developer/agent-apps/{app_id}/submit"),
Some(json!({"comments": comments})),
)
.await
}
pub async fn create_hosted_deployment(
&self,
app_id: &str,
request: HostedDeploymentRequest,
) -> Result<Value> {
self.request(
reqwest::Method::POST,
&format!("/portal/developer/agent-apps/{app_id}/hosting/deployments"),
Some(serde_json::to_value(request)?),
)
.await
}
async fn request(
&self,
method: reqwest::Method,
path: &str,
payload: Option<Value>,
) -> Result<Value> {
let mut request = self
.client
.request(method, format!("{}{}", self.hub_url, path))
.bearer_auth(&self.token);
if let Some(payload) = payload {
request = request.json(&payload);
}
Ok(request.send().await?.error_for_status()?.json().await?)
}
}
pub type DeveloperPlatformClient = DeveloperHubClient;
fn rust_runtime() -> String {
"rust".into()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn platform_client_uses_unified_platform_api() {
let client = DeveloperPlatformClient::for_platform("test-token").unwrap();
assert_eq!(client.hub_url, DEFAULT_PLATFORM_API_URL);
}
}