causa_kernel/ports/prepare/contract.rs
1//! Exclusive material preparation and its actual invocation configuration.
2
3use crate::{
4 CallControl, Context, ContextFrame, GenerationOptions, InvocationId, ModelRef, ToolSurface,
5};
6use async_trait::async_trait;
7
8/// Configuration visible while preparing this invocation's material.
9pub struct RoundInfo<'a> {
10 /// The actual logical model invocation being prepared.
11 pub invocation_id: &'a InvocationId,
12 /// The actual model selected by the caller.
13 pub model: &'a ModelRef,
14 /// The bound tools offered for this invocation.
15 pub tool_surface: &'a ToolSurface,
16 /// The generation settings selected by the caller.
17 pub generation: &'a GenerationOptions,
18}
19
20/// Failure to prepare a request's material.
21#[derive(Debug, thiserror::Error)]
22#[error("{message}")]
23pub struct PrepareError {
24 /// Human-readable failure detail.
25 pub message: String,
26}
27
28/// Prepares an independent request frame with exclusive access to context.
29///
30/// Each context edit commits independently; edits already committed remain if
31/// preparation subsequently fails. The returned frame is not written back to
32/// context. Input consumption and recovery belong to the implementation.
33#[async_trait]
34pub trait ContextPreparer: Send + Sync {
35 /// Selects and optionally edits material using actual invocation settings.
36 async fn prepare(
37 &self,
38 context: &mut Context,
39 round: &RoundInfo<'_>,
40 control: &CallControl,
41 ) -> Result<ContextFrame, PrepareError>;
42}