use causa_kernel::{
BatchError, BlockId, ControlError, ProcessorError, SourceError, ToolResultPayload,
};
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum ToolRegistryError {
#[error("duplicate static tool: {name}")]
DuplicateTool {
name: String,
},
#[error("dynamic source already registered: {source_id}")]
DuplicateSource {
source_id: String,
},
#[error("no dynamic source registered: {source_id}")]
UnknownSource {
source_id: String,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ToolCatalogError {
#[error(transparent)]
Control(ControlError),
#[error("source {source_id} failed: {error}")]
Source {
source_id: String,
error: SourceError,
},
#[error("duplicate advertised tool: {name}")]
DuplicateTool {
name: String,
},
#[error("static tool name changed from {registered} to {actual}")]
StaticNameChanged {
registered: String,
actual: String,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ToolProcessorPhase {
Before,
After,
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ToolProcessingError {
#[error(transparent)]
Control(ControlError),
#[error("invalid tool batch: {0}")]
InvalidBatch(BatchError),
#[error("tool batch already contains {completed} completed calls")]
NotFreshBatch {
completed: usize,
},
#[error("{phase:?} processor {index} failed: {error}")]
Processor {
phase: ToolProcessorPhase,
index: usize,
error: ProcessorError,
},
#[error("{phase:?} processor {index} returned an invalid batch: {error}")]
InvalidProcessorBatch {
phase: ToolProcessorPhase,
index: usize,
error: BatchError,
},
#[error("{phase:?} processor {index} violated its handoff: {message}")]
Handoff {
phase: ToolProcessorPhase,
index: usize,
message: String,
},
#[error("tool result rejected for declaration {call_block_id:?}: {error}")]
ResultRejected {
call_block_id: BlockId,
error: BatchError,
result: ToolResultPayload,
},
}