repositories / smith
smith
There are many coding harnesses - but this one is fast
owned by admin
plugins/echo/src/lib.rs
Raw//! Reference system plugin: one echo tool over the smith:plugin world.
#![expect(missing_docs, reason = "wit-bindgen generates the world surface")]
#![expect(clippy::pedantic, reason = "wit-bindgen generates the world surface")]
wit_bindgen::generate!({
path: "../../wit/smith-plugin.wit",
world: "plugin-world",
});
use exports::smith::plugin::plugin::{Guest, ToolDeclaration};
use exports::smith::plugin::provider::{
CatalogSnapshot, DecodeStep, Guest as ProviderGuest, ProviderRequest, ProviderSettings,
RequestTemplate, SettingsProvenance,
};
use exports::smith::plugin::registration::{Guest as RegistrationGuest, Registrations};
struct EchoPlugin;
impl RegistrationGuest for EchoPlugin {
fn declare() -> Registrations {
Registrations {
credential_sources: Vec::new(),
providers: Vec::new(),
models: Vec::new(),
}
}
}
impl ProviderGuest for EchoPlugin {
fn declare_settings() -> ProviderSettings {
ProviderSettings {
include_usage: false,
subscription: false,
provenance: SettingsProvenance::BuiltIn,
}
}
fn validate_settings(_settings: ProviderSettings) -> Result<ProviderSettings, String> {
Err("echo does not provide protocol settings".to_string())
}
fn build_request(
_model: String,
_request: ProviderRequest,
_settings: ProviderSettings,
_catalog: CatalogSnapshot,
) -> Result<RequestTemplate, String> {
Err("echo does not provide a model codec".to_string())
}
fn decode_response(
_state: Vec<u8>,
_chunk: Vec<u8>,
_finished: bool,
) -> Result<DecodeStep, String> {
Err("echo does not provide a model decoder".to_string())
}
}
impl Guest for EchoPlugin {
fn declare_tools() -> Vec<ToolDeclaration> {
vec![ToolDeclaration {
name: "echo".to_string(),
description: "Echoes the input string back verbatim.".to_string(),
input_schema_json: r#"{"type":"object","properties":{},"required":[]}"#.to_string(),
}]
}
fn invoke(name: String, input_json: String) -> Result<String, String> {
if name == "echo" {
Ok(input_json)
} else {
Err(format!("unknown tool: {name}"))
}
}
}
export!(EchoPlugin);