use std::collections::HashMap;
use crate::inbox::{InboxReceiver, InboxSender};
use awaken_contract::contract::inference::InferenceOverride;
use awaken_contract::contract::message::Message;
use awaken_contract::contract::storage::{RunRecord, RunRequestOrigin};
use awaken_contract::contract::suspension::ToolCallResume;
use awaken_contract::contract::tool::ToolDescriptor;
use awaken_contract::contract::tool_intercept::{AdapterKind, RunMode};
#[non_exhaustive]
pub struct ThreadContextSnapshot {
pub messages: Vec<Message>,
pub latest_run: Option<RunRecord>,
pub run_cache: HashMap<String, RunRecord>,
}
impl ThreadContextSnapshot {
#[must_use]
pub fn new(
messages: Vec<Message>,
latest_run: Option<RunRecord>,
run_cache: HashMap<String, RunRecord>,
) -> Self {
Self {
messages,
latest_run,
run_cache,
}
}
}
pub struct RunInbox {
pub sender: InboxSender,
pub receiver: InboxReceiver,
}
pub struct RunRequest {
pub messages: Vec<Message>,
pub messages_already_persisted: bool,
pub thread_id: String,
pub agent_id: Option<String>,
pub overrides: Option<InferenceOverride>,
pub decisions: Vec<(String, ToolCallResume)>,
pub frontend_tools: Vec<ToolDescriptor>,
pub origin: RunRequestOrigin,
pub run_mode: RunMode,
pub adapter: AdapterKind,
pub parent_run_id: Option<String>,
pub parent_thread_id: Option<String>,
pub continue_run_id: Option<String>,
pub run_id_hint: Option<String>,
pub dispatch_id_hint: Option<String>,
pub dispatch_id: Option<String>,
pub session_id: Option<String>,
pub transport_request_id: Option<String>,
pub run_inbox: Option<RunInbox>,
}
impl RunRequest {
pub fn new(thread_id: impl Into<String>, messages: Vec<Message>) -> Self {
Self {
messages,
messages_already_persisted: false,
thread_id: thread_id.into(),
agent_id: None,
overrides: None,
decisions: Vec::new(),
frontend_tools: Vec::new(),
origin: RunRequestOrigin::User,
run_mode: RunMode::Foreground,
adapter: AdapterKind::Internal,
parent_run_id: None,
parent_thread_id: None,
continue_run_id: None,
run_id_hint: None,
dispatch_id_hint: None,
dispatch_id: None,
session_id: None,
transport_request_id: None,
run_inbox: None,
}
}
#[must_use]
pub fn with_agent_id(mut self, agent_id: impl Into<String>) -> Self {
self.agent_id = Some(agent_id.into());
self
}
#[must_use]
pub fn with_overrides(mut self, overrides: InferenceOverride) -> Self {
self.overrides = Some(overrides);
self
}
#[must_use]
pub fn with_decisions(mut self, decisions: Vec<(String, ToolCallResume)>) -> Self {
self.decisions = decisions;
self
}
#[must_use]
pub fn with_frontend_tools(mut self, tools: Vec<ToolDescriptor>) -> Self {
self.frontend_tools = tools;
self
}
#[must_use]
pub fn with_origin(mut self, origin: RunRequestOrigin) -> Self {
self.origin = origin;
self
}
#[must_use]
pub fn with_run_mode(mut self, run_mode: RunMode) -> Self {
self.run_mode = run_mode;
self
}
#[must_use]
pub fn with_adapter(mut self, adapter: AdapterKind) -> Self {
self.adapter = adapter;
self
}
#[must_use]
pub fn with_parent_run_id(mut self, parent_run_id: impl Into<String>) -> Self {
self.parent_run_id = Some(parent_run_id.into());
self
}
#[must_use]
pub fn with_parent_thread_id(mut self, parent_thread_id: impl Into<String>) -> Self {
self.parent_thread_id = Some(parent_thread_id.into());
self
}
#[must_use]
pub fn with_continue_run_id(mut self, continue_run_id: impl Into<String>) -> Self {
self.continue_run_id = Some(continue_run_id.into());
self
}
#[must_use]
pub fn with_run_id_hint(mut self, run_id_hint: impl Into<String>) -> Self {
self.run_id_hint = Some(run_id_hint.into());
self
}
#[must_use]
pub fn with_dispatch_id_hint(mut self, dispatch_id_hint: impl Into<String>) -> Self {
self.dispatch_id_hint = Some(dispatch_id_hint.into());
self
}
#[must_use]
pub fn with_trace_dispatch_id(mut self, dispatch_id: impl Into<String>) -> Self {
self.dispatch_id = Some(dispatch_id.into());
self
}
#[must_use]
pub fn with_dispatch_id(mut self, dispatch_id: impl Into<String>) -> Self {
self.dispatch_id = Some(dispatch_id.into());
self
}
#[must_use]
pub fn with_session_id(mut self, session_id: impl Into<String>) -> Self {
self.session_id = Some(session_id.into());
self
}
#[must_use]
pub fn with_transport_request_id(mut self, transport_request_id: impl Into<String>) -> Self {
self.transport_request_id = Some(transport_request_id.into());
self
}
#[must_use]
pub fn with_inbox(mut self, sender: InboxSender, receiver: InboxReceiver) -> Self {
self.run_inbox = Some(RunInbox { sender, receiver });
self
}
#[must_use]
pub fn with_messages_already_persisted(mut self, value: bool) -> Self {
self.messages_already_persisted = value;
self
}
}