use crate::schema::graph::SchemaGraph;
use crate::schema::schema_type::SchemaType;
use crate::schema::schema_value::SchemaValue;
use serde::{Deserialize, Serialize};
pub mod argv;
pub mod canonical;
pub mod compatibility;
pub mod constraints;
mod process_exit_status;
pub use process_exit_status::ProcessExitStatus;
#[cfg(feature = "full")]
mod protobuf;
pub mod validation;
#[cfg(all(
any(feature = "guest", feature = "host"),
not(all(feature = "guest", feature = "host"))
))]
pub mod wit;
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(transparent))]
#[serde(transparent)]
pub struct CommandIndex(pub i32);
impl CommandIndex {
pub fn as_usize(self) -> Option<usize> {
usize::try_from(self.0).ok()
}
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct Tool {
pub version: String,
pub requires_filesystem: bool,
pub commands: CommandTree,
#[serde(default = "SchemaGraph::empty")]
pub schema: SchemaGraph,
}
impl Tool {
pub fn name(&self) -> Option<&str> {
self.commands.nodes.first().map(|node| node.name.as_str())
}
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct ToolMiddleware {
pub name: String,
pub version: String,
pub aliases: Vec<String>,
pub doc: Doc,
pub scope: ToolMiddlewareScope,
pub parameter_schema: SchemaGraph,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
pub enum ToolMiddlewareScope {
Monomorphic(Box<MonomorphicToolMiddlewareScope>),
Universal,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct MonomorphicToolMiddlewareScope {
pub presented: Tool,
pub expected: Option<Tool>,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct CommandTree {
pub nodes: Vec<CommandNode>,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct CommandNode {
pub name: String,
pub aliases: Vec<String>,
pub doc: Doc,
pub globals: Globals,
pub subcommands: Vec<CommandIndex>,
pub body: Option<CommandBody>,
}
#[derive(
Debug,
Clone,
PartialEq,
Default,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct Globals {
pub options: Vec<OptionSpec>,
pub flags: Vec<FlagSpec>,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct CommandBody {
pub positionals: Positionals,
pub options: Vec<OptionSpec>,
pub flags: Vec<FlagSpec>,
pub constraints: Vec<Constraint>,
pub stdin: Option<StreamSpec>,
pub stdout: Option<StreamSpec>,
pub stderr: Option<StreamSpec>,
pub result: Option<ResultSpec>,
pub errors: Vec<ErrorCase>,
pub annotations: Option<CommandAnnotations>,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct CommandAnnotations {
pub read_only: bool,
pub destructive: bool,
pub idempotent: bool,
pub open_world: bool,
}
#[derive(
Debug,
Clone,
PartialEq,
Default,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct Positionals {
pub fixed: Vec<Positional>,
pub tail: Option<TailPositional>,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct Positional {
pub name: String,
pub doc: Doc,
pub value_name: Option<String>,
pub type_: SchemaType,
pub default: Option<SchemaValue>,
pub required: bool,
pub accepts_stdio: bool,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct TailPositional {
pub name: String,
pub doc: Doc,
pub value_name: Option<String>,
pub item_type: SchemaType,
pub min: u32,
pub max: Option<u32>,
pub separator: Option<String>,
pub verbatim: bool,
pub accepts_stdio: bool,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct OptionSpec {
pub long: String,
pub short: Option<char>,
pub aliases: Vec<String>,
pub doc: Doc,
pub value_name: Option<String>,
pub shape: OptionShape,
pub default: Option<SchemaValue>,
pub required: bool,
pub env_var: Option<String>,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
pub enum OptionShape {
Scalar(SchemaType),
OptionalScalar(SchemaType),
RepeatableList(RepeatableListShape),
RepeatableMap(RepeatableMapShape),
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct RepeatableListShape {
pub repetition: Repetition,
pub item_type: SchemaType,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct RepeatableMapShape {
pub repetition: Repetition,
pub map_type: SchemaType,
pub duplicate_key_policy: DuplicateKeyPolicy,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "kebab-case")]
pub enum DuplicateKeyPolicy {
Reject,
LastWins,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
pub enum Repetition {
Repeated,
Delimited(char),
Either(char),
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct FlagSpec {
pub long: String,
pub short: Option<char>,
pub aliases: Vec<String>,
pub doc: Doc,
pub shape: FlagShape,
pub env_var: Option<String>,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
pub enum FlagShape {
BoolFlag(BoolFlagShape),
CountFlag(Option<u32>),
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct BoolFlagShape {
pub default: bool,
pub negatable: bool,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
pub enum Ref {
Present(String),
ValueIs(ValueIsRef),
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct ValueIsRef {
pub name: String,
pub value: SchemaValue,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
pub enum Constraint {
RequiresAll(Vec<Ref>),
AllOrNone(Vec<Ref>),
RequiresAny(Vec<Ref>),
MutexGroups(Vec<RefGroup>),
Implies(ImpliesC),
Forbids(ForbidsC),
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct RefGroup {
pub refs: Vec<Ref>,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct ImpliesC {
pub lhs_quant: Quantifier,
pub lhs: Vec<Ref>,
pub rhs_quant: Quantifier,
pub rhs: Vec<Ref>,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct ForbidsC {
pub lhs_quant: Quantifier,
pub lhs: Vec<Ref>,
pub rhs: Vec<Ref>,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "kebab-case")]
pub enum Quantifier {
All,
Any,
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct StreamSpec {
pub doc: Doc,
pub mime: Vec<String>,
pub required: bool,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename = "ToolResultSpec")]
pub struct ResultSpec {
pub type_: SchemaType,
pub doc: Doc,
pub formatters: Vec<Formatter>,
pub default_formatter: String,
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct Formatter {
pub name: String,
pub doc: Doc,
}
#[derive(
Debug,
Clone,
PartialEq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct ErrorCase {
pub name: String,
pub doc: Doc,
pub kind: ErrorKind,
pub exit_code: u8,
pub payload: Option<SchemaType>,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "kebab-case")]
pub enum ErrorKind {
UsageError,
RuntimeError,
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Default,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct Doc {
pub summary: String,
pub description: String,
pub examples: Vec<Example>,
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Serialize,
Deserialize,
golem_schema_derive::IntoSchema,
golem_schema_derive::FromSchema,
)]
#[cfg_attr(
feature = "full",
derive(desert_rust::BinaryCodec, golem_schema_derive::PoemSchema)
)]
#[cfg_attr(feature = "full", desert(evolution()))]
pub struct Example {
pub title: String,
pub body: String,
}