Skip to main content

agentspec_provider/
types.rs

1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3
4/// A request to an AI provider.
5#[derive(Debug, Clone)]
6pub struct AiRequest {
7    /// System prompt that sets the AI's behavior.
8    pub system_prompt: String,
9    /// User prompt with the actual task.
10    pub user_prompt: String,
11    /// Optional JSON schema for structured output.
12    pub json_schema: Option<String>,
13    /// Working directory for tool execution.
14    pub working_dir: String,
15}
16
17/// Token usage statistics.
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct AiUsage {
20    pub input_tokens: u64,
21    pub output_tokens: u64,
22    pub cost_usd: Option<f64>,
23}
24
25/// A response from an AI provider.
26#[derive(Debug, Clone)]
27pub struct AiResponse {
28    pub text: String,
29    pub usage: Option<AiUsage>,
30}
31
32/// Real-time events emitted during an AI request.
33#[derive(Debug, Clone)]
34pub enum AiEvent {
35    /// A tool was called by the AI.
36    ToolCall { tool: String, input: String },
37}
38
39/// Trait for AI backends that can process requests.
40///
41/// Implementors provide access to an AI model, either through a local CLI tool
42/// (Tier 1) or a direct HTTP API client (Tier 2, future).
43#[async_trait]
44pub trait AiProvider: Send + Sync {
45    /// Human-readable name of this provider (e.g., "claude", "gemini").
46    fn name(&self) -> &str;
47
48    /// Check whether this provider is available (e.g., CLI tool is installed).
49    async fn is_available(&self) -> bool;
50
51    /// Send a request to the AI provider.
52    ///
53    /// If `events` is provided, real-time events (like tool calls) are sent
54    /// through the channel during processing.
55    async fn request(
56        &self,
57        req: &AiRequest,
58        events: Option<tokio::sync::mpsc::UnboundedSender<AiEvent>>,
59    ) -> anyhow::Result<AiResponse>;
60}