pub mod google;
use anyhow::anyhow;
use systemprompt_ai::{UpstreamCall, UpstreamTarget, UpstreamTargetError};
use systemprompt_models::services::ProviderEntry;
use systemprompt_security::credential::{CredentialError, CredentialScope, fill_endpoint};
use super::DispatchError;
pub fn fill_project(endpoint: &str, project: Option<&str>) -> Result<String, CredentialError> {
let scope = CredentialScope {
project: project.map(str::to_owned),
..CredentialScope::empty()
};
fill_endpoint(endpoint, &scope)
}
pub(super) async fn resolve(provider: &ProviderEntry) -> Result<UpstreamCall, DispatchError> {
let target = UpstreamTarget::from_secrets(provider).map_err(pre_audit)?;
target.call().await.map_err(pre_audit)
}
fn pre_audit(error: UpstreamTargetError) -> DispatchError {
DispatchError::PreAudit(anyhow!(error))
}