Public declaration syntax from forge-rs/crates/forge-contracts/src/brew.rs Original source SHA-256: 9ffac728e785247fa8415b577a2d9809b646d2d2d00d78d1e8fcd9157b521680 Function bodies and constant values are omitted. This is not the complete implementation. Source line 41 pub const CONTRACT_VERSION: &str; Source line 48 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct PlanHandle { /// Unique plan identifier. pub plan_id: String, /// The Brew graph identifier this plan was frozen from. pub brew_id: String, /// Number of nodes in the plan. pub node_count: u32, /// Number of edges in the plan. pub edge_count: u32, /// Whether this plan is currently executing. pub executing: bool } Source line 69 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BrewNodeSpec { /// Unique node identifier within the brew. pub node_id: String, /// The type of node. pub node_type: BrewNodeType, /// Input mapping: key is parameter name, value is source expression. pub inputs: BTreeMap, /// Configuration specific to the node type. pub config: serde_json::Value } Source line 85 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum BrewNodeType { /// An agent execution node (runs a tool loop). Agent, /// A tool invocation node (calls a single tool). Tool, /// A provider call node (single LLM inference). Inference, /// A conditional branch node. Condition, /// A data transformation node. Transform, /// A sub-brew reference node. SubBrew, } Source line 102 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BrewEdgeSpec { /// Source node ID. pub from_node: String, /// Target node ID. pub to_node: String, /// The type of edge. pub edge_type: BrewEdgeType, /// Optional condition expression for conditional edges. pub condition: Option } Source line 118 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum BrewEdgeType { /// Data flows from source output to target input. Data, /// Control flow: target executes after source completes. Control, /// Error flow: target executes if source fails. Error, } Source line 129 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PlanExecutionResult { /// The plan that was executed. pub plan_id: String, /// Whether the plan completed successfully. pub success: bool, /// Results from each node, keyed by node ID. pub node_results: BTreeMap, /// Total execution time in milliseconds. pub duration_ms: u64, /// Total tokens consumed across all nodes. pub total_tokens: u64 } Source line 148 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct NodeResult { /// The node identifier. pub node_id: String, /// Whether this node succeeded. pub success: bool, /// The node's output as JSON. pub output: Option, /// Error message if the node failed. pub error: Option, /// Execution time for this node in milliseconds. pub duration_ms: u64 } Source line 185 #[async_trait] pub trait BrewContract: Send + Sync { /// Creates a new empty Brew graph. /// /// # Arguments /// /// * `brew_id` - Unique identifier for this brew. /// * `description` - Human-readable description of the plan's purpose. /// /// # Returns /// /// A handle to the unfrozen plan. async fn create_plan(&self, brew_id: &str, description: &str) -> ContractResult; /// Adds a node to an unfrozen plan. /// /// # Arguments /// /// * `plan_id` - The plan to modify. /// * `node` - The node specification. /// /// # Errors /// /// - `ContractError::PlanResolutionFailed` if the plan is already frozen. async fn add_node(&self, plan_id: &str, node: BrewNodeSpec) -> ContractResult<()>; /// Adds an edge to an unfrozen plan. /// /// # Arguments /// /// * `plan_id` - The plan to modify. /// * `edge` - The edge specification. /// /// # Errors /// /// - `ContractError::PlanResolutionFailed` if the plan is already frozen /// or if referenced nodes do not exist. async fn add_edge(&self, plan_id: &str, edge: BrewEdgeSpec) -> ContractResult<()>; /// Freezes a plan, validating and resolving all symbols. /// /// After freezing, no modifications are allowed. The plan is ready /// for execution. /// /// # Arguments /// /// * `plan_id` - The plan to freeze. /// /// # Returns /// /// The updated plan handle with `executing: false`. /// /// # Errors /// /// - `ContractError::PlanResolutionFailed` if validation fails. async fn freeze_plan(&self, plan_id: &str) -> ContractResult; /// Executes a frozen plan. /// /// # Arguments /// /// * `plan_id` - The frozen plan to execute. /// * `inputs` - Input values keyed by parameter name. /// /// # Returns /// /// The execution result with outputs from all nodes. /// /// # Errors /// /// - `ContractError::PlanExecutionFailed` if execution fails. async fn execute_plan( &self, plan_id: &str, inputs: BTreeMap, ) -> ContractResult; /// Queries the current status of a plan. /// /// # Arguments /// /// * `plan_id` - The plan to query. async fn get_plan_status(&self, plan_id: &str) -> ContractResult; }