Skip to main content

sim_lib_openai_server/plan/
address.rs

1use sim_kernel::{Error, Result, Symbol};
2
3/// Resolved description of a plan atom address, identifying the backend that
4/// should serve it.
5#[derive(Clone, Debug, PartialEq, Eq)]
6pub struct BackendDescriptor {
7    /// Full atom address (for example `openai/gpt-4o`).
8    pub address: String,
9    /// Leading address segment naming the backend family (for example `openai`).
10    pub head: String,
11    /// Runner symbol derived from the full address.
12    pub runner: Symbol,
13    /// Whether the address designates a built-in fixture backend.
14    pub fixture: bool,
15}
16
17/// Resolves an atom address into a [`BackendDescriptor`], erroring when the
18/// backend head is unknown.
19pub fn resolve_atom_address(address: &str) -> Result<BackendDescriptor> {
20    let Some((head, _)) = address.split_once('/') else {
21        return Err(model_not_found(address));
22    };
23    if !KNOWN_HEADS.contains(&head) {
24        return Err(model_not_found(address));
25    }
26    Ok(BackendDescriptor {
27        address: address.to_owned(),
28        head: head.to_owned(),
29        runner: Symbol::new(address.to_owned()),
30        fixture: head == "fixture",
31    })
32}
33
34fn model_not_found(address: &str) -> Error {
35    Error::Eval(format!("model_not_found: {address}"))
36}
37
38const KNOWN_HEADS: &[&str] = &[
39    "openai", "ollama", "process", "runner", "agent", "skill", "sim", "fixture", "gateway",
40];