graphrt-core 0.6.5

Executor-agnostic graph runtime for agentic AI workflows: graph model, variable pool, scheduler, events, snapshots and built-in control nodes.
Documentation
//! What a host gives a workflow it did not write (a bundle's) of its own
//! environment: the names that read like a credential or a setting of the
//! host, which a host gives only when it says so twice, and the names a host's
//! own config files read. Shared by every host: `graphrt serve` and `run`, and
//! the embedded runtimes (`graphrt-ffi`).

/// Prefixes of variables that hold credentials or settings of the host.
pub const CREDENTIAL_PREFIXES: &[&str] = &[
    "GRAPHRT_",
    "AWS_",
    "GOOGLE_",
    "GCP_",
    "GCLOUD_",
    "AZURE_",
    "FLY_",
    "OPENAI_",
    "ANTHROPIC_",
    "GEMINI_",
    "BEDROCK_",
    "TYPESAFE_",
    "OLLAMA_",
    "COHERE_",
    "QDRANT_",
    "LANGFUSE_",
    "OTEL_",
    "TELEGRAM_",
    "SLACK_",
    "WHATSAPP_",
    "TEAMS_",
    "MICROSOFT_",
    "KUBERNETES_",
    "DOCKER_",
    "GITHUB_",
    "GH_",
    "GITLAB_",
    "CI_",
    "ACTIONS_",
    "SSH_",
    "LANGSMITH_",
    "BRAINTRUST_",
    "OPIK_",
    "PHOENIX_",
    "MLFLOW_",
    "HF_",
    "MISTRAL_",
    "GROQ_",
    "OPENROUTER_",
    "CLOUDFLARE_",
];

/// Whole names of credentials of the host.
pub const CREDENTIAL_NAMES: &[&str] = &[
    "HOME",
    "PATH",
    "USER",
    "KUBECONFIG",
    "NPM_TOKEN",
    "CARGO_REGISTRY_TOKEN",
    "DATABASE_URL",
    "PGPASSWORD",
    "SUPABASE_JWT_SECRET",
];

/// Whether `name` is a credential or a setting of the host: by its prefix or
/// whole name, or a variable the host's own config files read (`host_reads`).
pub fn is_credential(name: &str, host_reads: &[String]) -> bool {
    CREDENTIAL_PREFIXES.iter().any(|prefix| name.starts_with(prefix))
        || CREDENTIAL_NAMES.contains(&name)
        || host_reads.iter().any(|read| read == name)
}

/// The variables a host config names: `*_env` fields, `var` of a credentials
/// entry, the keys of an `env` object and the items of `pass_env`.
pub fn collect_env_names(value: &serde_json::Value, names: &mut Vec<String>) {
    match value {
        serde_json::Value::Object(fields) => {
            for (key, value) in fields {
                if let (true, Some(name)) = (key.ends_with("_env") || key == "var", value.as_str()) {
                    names.push(name.to_owned());
                }
                // An MCP server's own environment: the names it is given.
                if key == "env"
                    && let Some(env) = value.as_object()
                {
                    names.extend(env.keys().cloned());
                }
                if key == "pass_env"
                    && let Some(list) = value.as_array()
                {
                    names.extend(list.iter().filter_map(serde_json::Value::as_str).map(str::to_owned));
                }
                collect_env_names(value, names);
            }
        }
        serde_json::Value::Array(items) => items.iter().for_each(|item| collect_env_names(item, names)),
        _ => {}
    }
}

/// `${VAR}` references in `text`.
pub fn collect_references(text: &str, names: &mut Vec<String>) {
    let mut rest = text;
    while let Some(start) = rest.find("${") {
        let after = rest.get(start + 2..).unwrap_or_default();
        let Some(end) = after.find('}') else { break };
        if let Some(name) = after.get(..end) {
            names.push(name.to_owned());
        }
        rest = after.get(end..).unwrap_or_default();
    }
}