use crate::error::Result;
use crate::typed_id::{MessageId, SessionId};
use async_trait::async_trait;
#[derive(Debug)]
pub enum ToolCallClaimResult {
Claimed { claim_token: uuid::Uuid },
AlreadySettled {
result_json: serde_json::Value,
args_fingerprint: String,
},
AlreadyRunning { args_fingerprint: String },
DeterminismViolation {
stored_fingerprint: String,
current_fingerprint: String,
},
}
#[derive(Debug, Clone)]
pub enum DurableToolCallStatus {
Settled { result_json: serde_json::Value },
Interrupted {
result_json: Option<serde_json::Value>,
},
Running,
}
#[async_trait]
pub trait DurableToolResultStore: Send + Sync + 'static {
async fn try_claim_tool_call(
&self,
turn_id: &str,
tool_call_id: &str,
tool_name: &str,
args_fingerprint: &str,
) -> Result<ToolCallClaimResult>;
async fn settle_tool_call(
&self,
turn_id: &str,
tool_call_id: &str,
result_json: serde_json::Value,
status: &str,
claim_token: uuid::Uuid,
) -> Result<bool>;
async fn get_tool_call_status(
&self,
turn_id: &str,
tool_call_id: &str,
) -> Result<Option<DurableToolCallStatus>>;
}
#[derive(Debug, Clone)]
pub struct StreamProgress {
pub accumulated_len: usize,
pub last_delta_at: u64,
}
#[async_trait]
pub trait StreamHeartbeater: Send + Sync {
async fn heartbeat(&self, progress: StreamProgress);
}
#[derive(Debug, Clone)]
pub struct PartialStreamState {
pub reasoning_state: Option<everruns_contracts::reasoning_updates::ReasoningState>,
pub message_id: MessageId,
pub accumulated: String,
pub attempt_settled: bool,
}
#[async_trait]
pub trait PartialStreamStore: Send + Sync {
async fn get_partial_stream(
&self,
session_id: SessionId,
turn_id: &str,
) -> Result<Option<PartialStreamState>>;
}