use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompletionContext {
pub completion_id: String,
pub completion_ref: CompletionReference,
pub argument_name: Option<String>,
pub partial_value: Option<String>,
pub resolved_arguments: HashMap<String, String>,
pub completions: Vec<CompletionOption>,
pub cursor_position: Option<usize>,
pub max_completions: Option<usize>,
pub has_more: bool,
pub total_completions: Option<usize>,
pub client_capabilities: Option<CompletionCapabilities>,
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompletionCapabilities {
pub supports_pagination: bool,
pub supports_fuzzy: bool,
pub max_batch_size: usize,
pub supports_descriptions: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CompletionReference {
Prompt {
name: String,
argument: String,
},
ResourceTemplate {
name: String,
parameter: String,
},
Tool {
name: String,
argument: String,
},
Custom {
ref_type: String,
metadata: HashMap<String, serde_json::Value>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompletionOption {
pub value: String,
pub label: Option<String>,
pub completion_type: Option<String>,
pub documentation: Option<String>,
pub sort_priority: Option<i32>,
pub insert_text: Option<String>,
}
impl CompletionContext {
pub fn new(completion_ref: CompletionReference) -> Self {
Self {
completion_id: Uuid::new_v4().to_string(),
completion_ref,
argument_name: None,
partial_value: None,
resolved_arguments: HashMap::new(),
completions: Vec::new(),
cursor_position: None,
max_completions: Some(100),
has_more: false,
total_completions: None,
client_capabilities: None,
metadata: HashMap::new(),
}
}
pub fn add_completion(&mut self, option: CompletionOption) {
self.completions.push(option);
}
pub fn with_resolved_arguments(mut self, args: HashMap<String, String>) -> Self {
self.resolved_arguments = args;
self
}
}