stackless_integrations/providers/agentphone/
number.rs1use 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};
12use crate::registry;
13
14pub const RESOURCE_KIND: &str = "integration-agentphone";
15
16#[derive(Debug, Serialize)]
17pub struct AgentPhoneNumberConfig {
18 pub agent_name: String,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub area_code: Option<String>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub country: Option<String>,
23}
24
25impl CatalogService for AgentPhoneNumberConfig {
26 const REFERENCE: &'static str = "agentphone/number";
27}
28
29#[derive(Debug)]
30pub struct AgentPhoneNumber;
31
32impl Hostable for AgentPhoneNumber {
33 const PROVIDER: &'static str = "agentphone";
34 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
35 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
36 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
37 const OUTPUTS: &'static [&'static str] = &["phone_number"];
38}
39
40impl FamilyResource for AgentPhoneNumber {
41 type Config = AgentPhoneNumberConfig;
42 const PROVIDER_PREFIX: &'static str = "AGENTPHONE";
43 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
45 &[("PHONE_NUMBER", "phone_number", true)];
46
47 fn build_config(
48 ctx: &ProvisionContext<'_>,
49 ) -> Result<AgentPhoneNumberConfig, IntegrationError> {
50 let config = super::integration_config(ctx)?;
51 Ok(AgentPhoneNumberConfig {
52 agent_name: super::interp_required(ctx, &config, "agent_name")?,
53 area_code: super::interp_optional(ctx, &config, "area_code")?,
54 country: super::interp_optional(ctx, &config, "country")?,
55 })
56 }
57}
58
59pub fn validate_config(
60 name: &str,
61 config: &BTreeMap<String, toml::Value>,
62) -> Result<(), IntegrationError> {
63 registry::config_string(config, "agent_name").map_err(|err| {
64 IntegrationError::ConfigInvalid {
65 location: format!("integrations.{name}.agent_name"),
66 detail: err.to_string(),
67 }
68 })?;
69 let _ = (name, config);
70 Ok(())
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76 use crate::ProviderOps;
77 use crate::resource::ResourcePayload;
78 use stackless_core::def::StackDef;
79 use stackless_stripe_projects::stripe::StripeProjects;
80 use stackless_stripe_projects::test_support;
81
82 #[test]
83 fn config_matches_catalog() {
84 const FIXTURE: &str = include_str!(concat!(
85 env!("CARGO_MANIFEST_DIR"),
86 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
87 ));
88 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
89 let failures = stackless_stripe_projects::verify_service(
90 &catalog,
91 &AgentPhoneNumberConfig {
92 agent_name: "test-agent_name".into(),
93 area_code: None,
94 country: None,
95 },
96 );
97 assert!(
98 failures.is_empty(),
99 "agentphone/number catalog gaps:\n{}",
100 failures.join("\n")
101 );
102 }
103
104 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_number","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_agentphone","provider_name":"AgentPhone","service_id":"number","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"paid"},"configuration_schema":{"properties":{"agent_name":{"description":"Name for the AI agent","type":"string"},"area_code":{"description":"Preferred 3-digit area code (optional)","type":"string"},"country":{"description":"Country for the phone number","enum":["US","CA"],"type":"string"}},"required":["agent_name"],"type":"object"}}]}}"##;
105
106 fn test_def() -> StackDef {
107 StackDef::parse(
108 r#"
109[stack]
110name = "atto"
111[stack.projects.stripe]
112project = "project_1"
113[integrations.res]
114provider = "agentphone"
115agent_name = "test-agent_name"
116[services.api]
117source = { repo = "r", ref = "main" }
118env = { OUT = "${integrations.res.phone_number}" }
119health = { path = "/health" }
120[services.api.local]
121run = "true"
122"#,
123 )
124 .unwrap()
125 }
126
127 #[tokio::test]
128 async fn provision_records_outputs() {
129 let runner = test_support::provision_script(
130 CATALOG_ENVELOPE,
131 serde_json::json!({"AGENTPHONE_PHONE_NUMBER": "val_phone_number"}),
132 0,
133 );
134 let dir = tempfile::tempdir().unwrap();
135 std::fs::write(
136 dir.path().join("stackless.toml"),
137 "[stack]\nname=\"atto\"\n",
138 )
139 .unwrap();
140 let stripe = StripeProjects::new(&runner, dir.path());
141
142 let resource = AgentPhoneNumber
143 .provision(
144 &stripe.as_dyn(),
145 &test_def(),
146 dir.path(),
147 "demo",
148 "res",
149 "local",
150 false,
151 )
152 .await
153 .unwrap();
154 assert_eq!(resource.resource_kind, "integration-agentphone");
155 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
156 assert_eq!(payload.outputs["phone_number"], "val_phone_number");
157 }
158}