Skip to main content

stackless_integrations/providers/elevenlabs/
tts.rs

1//! `elevenlabs/tts` integration.
2
3use std::collections::BTreeMap;
4
5use serde::Serialize;
6use stackless_stripe_projects::catalog::verify::CatalogService;
7use stackless_stripe_projects::provision::ProvisionContext;
8
9use super::FamilyResource;
10use crate::error::IntegrationError;
11use crate::hostable::{ConfigScope, Hostable, IntegrationHosting};
12
13pub const RESOURCE_KIND: &str = "integration-elevenlabs";
14
15#[derive(Debug, Serialize)]
16pub struct ElevenLabsTtsConfig {}
17
18impl CatalogService for ElevenLabsTtsConfig {
19    const REFERENCE: &'static str = "elevenlabs/tts";
20}
21
22#[derive(Debug)]
23pub struct ElevenLabsTts;
24
25impl Hostable for ElevenLabsTts {
26    const PROVIDER: &'static str = "elevenlabs";
27    const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
28    const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
29    const RESOURCE_KIND: &'static str = RESOURCE_KIND;
30    const OUTPUTS: &'static [&'static str] = &["api_key", "base_url"];
31}
32
33impl FamilyResource for ElevenLabsTts {
34    type Config = ElevenLabsTtsConfig;
35    const PROVIDER_PREFIX: &'static str = "ELEVENLABS";
36    const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
37        &[("API_KEY", "api_key", true), ("BASE_URL", "base_url", true)];
38
39    fn build_config(ctx: &ProvisionContext<'_>) -> Result<ElevenLabsTtsConfig, IntegrationError> {
40        let _ = super::integration_config(ctx)?;
41        Ok(ElevenLabsTtsConfig {})
42    }
43}
44
45pub fn validate_config(
46    name: &str,
47    config: &BTreeMap<String, toml::Value>,
48) -> Result<(), IntegrationError> {
49    let _ = (name, config);
50    Ok(())
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56    use crate::ProviderOps;
57    use crate::resource::ResourcePayload;
58    use stackless_core::def::StackDef;
59    use stackless_stripe_projects::stripe::StripeProjects;
60    use stackless_stripe_projects::test_support;
61
62    #[test]
63    fn config_matches_catalog() {
64        const FIXTURE: &str = include_str!(concat!(
65            env!("CARGO_MANIFEST_DIR"),
66            "/../stackless-stripe-projects/tests/fixtures/catalog.json"
67        ));
68        let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
69        let failures = stackless_stripe_projects::verify_service(&catalog, &ElevenLabsTtsConfig {});
70        assert!(
71            failures.is_empty(),
72            "elevenlabs/tts catalog gaps:\n{}",
73            failures.join("\n")
74        );
75    }
76
77    const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_tts","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_elevenlabs","provider_name":"ElevenLabs","service_id":"tts","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"free"},"configuration_schema":{"type":"object","required":[],"additionalProperties":false,"properties":{}}}]}}"##;
78
79    fn test_def() -> StackDef {
80        StackDef::parse(
81            r#"
82[stack]
83name = "atto"
84[stack.projects.stripe]
85project = "project_1"
86[integrations.res]
87provider = "elevenlabs"
88[services.api]
89source = { repo = "r", ref = "main" }
90env = { OUT = "${integrations.res.api_key}" }
91health = { path = "/health" }
92[services.api.local]
93run = "true"
94"#,
95        )
96        .unwrap()
97    }
98
99    #[tokio::test]
100    async fn provision_records_outputs() {
101        let runner = test_support::provision_script(
102            CATALOG_ENVELOPE,
103            serde_json::json!({"ELEVENLABS_API_KEY": "val_api_key", "ELEVENLABS_BASE_URL": "val_base_url"}),
104            0,
105        );
106        let dir = tempfile::tempdir().unwrap();
107        std::fs::write(
108            dir.path().join("stackless.toml"),
109            "[stack]\nname=\"atto\"\n",
110        )
111        .unwrap();
112        let stripe = StripeProjects::new(&runner, dir.path());
113
114        let resource = ElevenLabsTts
115            .provision(
116                &stripe.as_dyn(),
117                &test_def(),
118                dir.path(),
119                "demo",
120                "res",
121                "local",
122                false,
123            )
124            .await
125            .unwrap();
126        assert_eq!(resource.resource_kind, "integration-elevenlabs");
127        let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
128        assert_eq!(payload.outputs["api_key"], "val_api_key");
129        assert_eq!(payload.outputs["base_url"], "val_base_url");
130    }
131}