use std::path::PathBuf;
use basis::{
BuiltinProvider, ContextConfig, Effort, McpServer, ModelSelector, PersistedSession,
PreparedRun, RunError, ShellAccess, SystemPrompt, ToolsConfig, hooks::HooksConfig,
mcp::McpConfig, skills::SkillsConfig, templates::TemplatesConfig,
};
#[async_trait::async_trait]
pub trait SessionSource: Send + Sync + 'static {
async fn create(&self, cwd: PathBuf, mcp: Vec<McpServer>) -> Result<PreparedRun, RunError>;
async fn resume(
&self,
agent_id: &str,
cwd: PathBuf,
mcp: Vec<McpServer>,
) -> Result<PreparedRun, RunError> {
let _ = (agent_id, cwd, mcp);
Err(RunError::NoSuchSession)
}
fn lists_sessions(&self) -> bool {
false
}
async fn list_sessions(&self, cwd: PathBuf) -> Result<Vec<PersistedSession>, RunError> {
let _ = cwd;
Ok(Vec::new())
}
fn deletes_sessions(&self) -> bool {
false
}
async fn delete(&self, agent_id: &str) -> Result<(), RunError> {
let _ = agent_id;
Err(RunError::NoSuchSession)
}
}
#[derive(Debug, Clone, Default)]
pub struct Discovery {
pub context: ContextConfig,
pub skills: SkillsConfig,
pub templates: TemplatesConfig,
pub hooks: HooksConfig,
pub tools: ToolsConfig,
pub mcp: McpConfig,
}
#[derive(Debug, Clone, Default)]
pub struct SessionTemplate {
pub(crate) provider: Option<BuiltinProvider>,
pub(crate) base_url: Option<String>,
pub(crate) model: Option<ModelSelector>,
pub(crate) shell: ShellAccess,
pub(crate) system_prompt: Option<SystemPrompt>,
pub(crate) effort: Option<Effort>,
pub(crate) session_name: Option<String>,
pub(crate) discovery: Discovery,
}
impl SessionTemplate {
pub fn new() -> Self {
Self::default()
}
pub fn with_provider(self, provider: BuiltinProvider) -> Self {
Self {
provider: Some(provider),
..self
}
}
pub fn with_base_url(self, base_url: impl Into<String>) -> Self {
Self {
base_url: Some(base_url.into()),
..self
}
}
pub fn with_model(self, model: ModelSelector) -> Self {
Self {
model: Some(model),
..self
}
}
pub fn with_shell(self, shell: ShellAccess) -> Self {
Self { shell, ..self }
}
pub fn with_system_prompt(self, system_prompt: SystemPrompt) -> Self {
Self {
system_prompt: Some(system_prompt),
..self
}
}
pub fn with_effort(self, effort: Effort) -> Self {
Self {
effort: Some(effort),
..self
}
}
pub fn with_session_name(self, session_name: impl Into<String>) -> Self {
Self {
session_name: Some(session_name.into()),
..self
}
}
pub fn with_discovery(self, discovery: Discovery) -> Self {
Self { discovery, ..self }
}
}