Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

1.5 KB
Raw Blame
//! Host-owned optional ML callback served to the TinyJuice module.

use tinybus::ObjectPath;

// The module calls *out* to this one: the ML plain-text compressor is the
// host's, not the module's. The names come from the contract so the two sides
// cannot drift — a mismatch here is a `NameHasNoOwner` the module swallows by
// falling back to a compressor that needs no ML runtime, which is a silent
// loss of compression rather than a failure anyone sees.
use tinyjuice_bus::names::{ML_HOST_NAME as NAME, ML_HOST_PATH as PATH};

#[derive(Clone)]
struct MlHost;

#[tinybus::interface(name = "ai.tinyhumans.tinyjuice.MlHost")]
impl MlHost {
    /// One tool-less model call for the module's summary stage, run under the
    /// turn its `context_token` names. `None` declines — the token is unknown
    /// or already used, and the module falls back to its own compressors.
    async fn generate(
        &self,
        request: tinyjuice_bus::wire::GenerateRequest,
    ) -> tinybus::Result<Option<String>> {
        crate::inference::tokenjuice::generate::serve(request)
            .await
            .map_err(method_error)
    }
}

fn method_error(error: impl std::fmt::Display) -> tinybus::Error {
    tinybus::Error::MethodFailed {
        name: "ai.tinyhumans.tinyjuice.Error.Host".to_string(),
        message: error.to_string(),
    }
}

pub(super) async fn install(connection: &tinybus::Connection) -> tinybus::Result<()> {
    connection.serve_at(ObjectPath::new(PATH)?, MlHost).await?;
    connection.request_name(NAME).await
}