use super::{exec_with_env, find_on_path, run_with_env, server};
fn openclaw_model_id(model: &str) -> &str {
let bare = model.strip_prefix("docker.io/ai/").unwrap_or(model);
if bare.is_empty() {
"default"
} else {
bare
}
}
pub(super) fn launch_openclaw(model: &str, extra_args: &[String]) -> anyhow::Result<()> {
let bin =
find_on_path("openclaw").ok_or_else(|| anyhow::anyhow!("openclaw is not installed"))?;
let onboarded = dirs::home_dir().is_some_and(|h| {
h.join(".openclaw").join("openclaw.json").exists()
|| h.join(".clawdbot").join("clawdbot.json").exists()
});
if !onboarded {
let effective_model = openclaw_model_id(model);
let onboard = [
"onboard",
"--non-interactive",
"--accept-risk",
"--auth-choice",
"ollama",
"--custom-base-url",
&format!("{}/v1", server()),
"--custom-model-id",
effective_model,
"--skip-health",
"--skip-channels",
"--skip-skills",
]
.map(String::from);
let code = run_with_env(&bin, &onboard, &[])?;
anyhow::ensure!(code == 0, "openclaw onboarding failed");
}
exec_with_env(&bin, extra_args, &[])
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn openclaw_model_id_strips_the_docker_ai_prefix() {
assert_eq!(
openclaw_model_id("docker.io/ai/qwen3.5:0.8b"),
"qwen3.5:0.8b"
);
assert_eq!(openclaw_model_id("qwen3.5:0.8b"), "qwen3.5:0.8b");
assert_eq!(
openclaw_model_id("hf.co/unsloth/Qwen3.5-0.8B-GGUF"),
"hf.co/unsloth/Qwen3.5-0.8B-GGUF"
);
assert_eq!(openclaw_model_id(""), "default");
assert_eq!(openclaw_model_id("docker.io/ai/"), "default");
}
}