feat: add title field for data types (#410)
* feat(model): add title field to various structs * fix(test): fix test json schema * fix(model): allow boxed type in `ts_union` macro
This commit is contained in:
parent
fdd6bc0565
commit
1b70f5b032
2 changed files with 219 additions and 73 deletions
|
|
@ -10,6 +10,8 @@ use crate::common::{extract_doc_line, none_expr};
|
|||
pub struct PromptAttribute {
|
||||
/// The name of the prompt
|
||||
pub name: Option<String>,
|
||||
/// Human readable title of prompt
|
||||
pub title: Option<String>,
|
||||
/// Optional description of what the prompt does
|
||||
pub description: Option<String>,
|
||||
/// Arguments that can be passed to the prompt
|
||||
|
|
@ -18,6 +20,7 @@ pub struct PromptAttribute {
|
|||
|
||||
pub struct ResolvedPromptAttribute {
|
||||
pub name: String,
|
||||
pub title: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub arguments: Expr,
|
||||
}
|
||||
|
|
@ -28,18 +31,25 @@ impl ResolvedPromptAttribute {
|
|||
name,
|
||||
description,
|
||||
arguments,
|
||||
title,
|
||||
} = self;
|
||||
let description = if let Some(description) = description {
|
||||
quote! { Some(#description.into()) }
|
||||
} else {
|
||||
quote! { None }
|
||||
};
|
||||
let title = if let Some(title) = title {
|
||||
quote! { Some(#title.into()) }
|
||||
} else {
|
||||
quote! { None }
|
||||
};
|
||||
let tokens = quote! {
|
||||
pub fn #fn_ident() -> rmcp::model::Prompt {
|
||||
rmcp::model::Prompt {
|
||||
name: #name.into(),
|
||||
description: #description,
|
||||
arguments: #arguments,
|
||||
title: #title,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -87,6 +97,7 @@ pub fn prompt(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream>
|
|||
name: name.clone(),
|
||||
description: description.clone(),
|
||||
arguments: arguments.clone(),
|
||||
title: attribute.title,
|
||||
};
|
||||
let prompt_attr_fn = resolved_prompt_attr.into_fn(prompt_attr_fn_ident.clone())?;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ fn extract_schema_from_return_type(ret_type: &syn::Type) -> Option<Expr> {
|
|||
pub struct ToolAttribute {
|
||||
/// The name of the tool
|
||||
pub name: Option<String>,
|
||||
/// Human readable title of tool
|
||||
pub title: Option<String>,
|
||||
pub description: Option<String>,
|
||||
/// A JSON Schema object defining the expected parameters for the tool
|
||||
pub input_schema: Option<Expr>,
|
||||
|
|
@ -77,6 +79,7 @@ pub struct ToolAttribute {
|
|||
|
||||
pub struct ResolvedToolAttribute {
|
||||
pub name: String,
|
||||
pub title: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub input_schema: Expr,
|
||||
pub output_schema: Option<Expr>,
|
||||
|
|
@ -88,6 +91,7 @@ impl ResolvedToolAttribute {
|
|||
let Self {
|
||||
name,
|
||||
description,
|
||||
title,
|
||||
input_schema,
|
||||
output_schema,
|
||||
annotations,
|
||||
|
|
@ -102,10 +106,16 @@ impl ResolvedToolAttribute {
|
|||
} else {
|
||||
quote! { None }
|
||||
};
|
||||
let title = if let Some(title) = title {
|
||||
quote! { Some(#title.into()) }
|
||||
} else {
|
||||
quote! { None }
|
||||
};
|
||||
let tokens = quote! {
|
||||
pub fn #fn_ident() -> rmcp::model::Tool {
|
||||
rmcp::model::Tool {
|
||||
name: #name.into(),
|
||||
title: #title,
|
||||
description: #description,
|
||||
input_schema: #input_schema,
|
||||
output_schema: #output_schema,
|
||||
|
|
@ -229,6 +239,7 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
|
|||
input_schema: input_schema_expr,
|
||||
output_schema: output_schema_expr,
|
||||
annotations: annotations_expr,
|
||||
title: attribute.title,
|
||||
};
|
||||
let tool_attr_fn = resolved_tool_attr.into_fn(tool_attr_fn_ident)?;
|
||||
// modify the the input function
|
||||
|
|
|
|||
Loading…
Reference in a new issue