use serde::{Deserialize, Serialize};
use crate::protocol::{
Cursor,
Role,
Annotations,
Request,
Notification,
resources::{TextResourceContents, BlobResourceContents},
sampling::{TextContent, ImageContent, AudioContent},
};
use crate::protocol::messages::MessageResult;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Prompt {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub arguments: Option<Vec<PromptArgument>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PromptArgument {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub required: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PromptMessage {
pub role: Role,
#[serde(flatten)]
pub content: PromptContent,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum PromptContent {
Text(TextContent),
Image(ImageContent),
Audio(AudioContent),
Resource(EmbeddedResource),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct EmbeddedResource {
pub r#type: String,
pub resource: ResourceContents,
#[serde(skip_serializing_if = "Option::is_none")]
pub annotations: Option<Annotations>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum ResourceContents {
Text(TextResourceContents),
Blob(BlobResourceContents),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PromptReference {
pub r#type: String,
pub name: String,
}
impl PromptReference {
pub fn new(name: impl Into<String>) -> Self {
Self {
r#type: "ref/prompt".to_string(),
name: name.into(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ListPromptsRequest {
pub method: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub params: Option<ListPromptsParams>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ListPromptsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<Cursor>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ListPromptsResult {
pub prompts: Vec<Prompt>,
#[serde(skip_serializing_if = "Option::is_none")]
pub next_cursor: Option<Cursor>,
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
pub meta: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GetPromptRequest {
pub method: String,
pub params: GetPromptParams,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GetPromptParams {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub arguments: Option<std::collections::HashMap<String, String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GetPromptResult {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub messages: Vec<PromptMessage>,
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
pub meta: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PromptListChangedNotification {
pub method: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub params: Option<serde_json::Value>,
}
impl Request for ListPromptsRequest {
const METHOD: &'static str = "prompts/list";
fn method(&self) -> &str {
&self.method
}
fn params(&self) -> Option<&serde_json::Value> {
None
}
}
impl Request for GetPromptRequest {
const METHOD: &'static str = "prompts/get";
fn method(&self) -> &str {
&self.method
}
fn params(&self) -> Option<&serde_json::Value> {
None
}
}
impl Notification for PromptListChangedNotification {
const METHOD: &'static str = "notifications/prompts/list_changed";
fn method(&self) -> &str {
&self.method
}
fn params(&self) -> Option<&serde_json::Value> {
None
}
}
impl MessageResult for ListPromptsResult {}
impl MessageResult for GetPromptResult {}
impl ListPromptsRequest {
pub fn new() -> Self {
Self {
method: Self::METHOD.to_string(),
params: None,
}
}
pub fn with_cursor(cursor: impl Into<String>) -> Self {
Self {
method: Self::METHOD.to_string(),
params: Some(ListPromptsParams {
cursor: Some(cursor.into()),
}),
}
}
}
impl GetPromptRequest {
pub fn new(name: impl Into<String>) -> Self {
Self {
method: Self::METHOD.to_string(),
params: GetPromptParams {
name: name.into(),
arguments: None,
},
}
}
pub fn with_arguments(
name: impl Into<String>,
arguments: std::collections::HashMap<String, String>,
) -> Self {
Self {
method: Self::METHOD.to_string(),
params: GetPromptParams {
name: name.into(),
arguments: Some(arguments),
},
}
}
}
impl PromptListChangedNotification {
pub fn new() -> Self {
Self {
method: Self::METHOD.to_string(),
params: None,
}
}
}