feat: remove concrete impl of get_prompt and list_prompts, and require
implementing types to define them, similar to other methods
This commit is contained in:
parent
22b11ea127
commit
7afab42c61
1 changed files with 10 additions and 17 deletions
|
|
@ -97,12 +97,8 @@ pub trait Router: Send + Sync + 'static {
|
||||||
&self,
|
&self,
|
||||||
uri: &str,
|
uri: &str,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<String, ResourceError>> + Send + 'static>>;
|
) -> Pin<Box<dyn Future<Output = Result<String, ResourceError>> + Send + 'static>>;
|
||||||
fn list_prompts(&self) -> Option<Vec<Prompt>> {
|
fn list_prompts(&self) -> Vec<Prompt>;
|
||||||
None
|
fn get_prompt(&self, prompt_name: &str) -> PromptFuture;
|
||||||
}
|
|
||||||
fn get_prompt(&self, _prompt_name: &str) -> Option<PromptFuture> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper method to create base response
|
// Helper method to create base response
|
||||||
fn create_response(&self, id: Option<u64>) -> JsonRpcResponse {
|
fn create_response(&self, id: Option<u64>) -> JsonRpcResponse {
|
||||||
|
|
@ -257,7 +253,7 @@ pub trait Router: Send + Sync + 'static {
|
||||||
req: JsonRpcRequest,
|
req: JsonRpcRequest,
|
||||||
) -> impl Future<Output = Result<JsonRpcResponse, RouterError>> + Send {
|
) -> impl Future<Output = Result<JsonRpcResponse, RouterError>> + Send {
|
||||||
async move {
|
async move {
|
||||||
let prompts = self.list_prompts().unwrap_or_default();
|
let prompts = self.list_prompts();
|
||||||
|
|
||||||
let result = ListPromptsResult { prompts };
|
let result = ListPromptsResult { prompts };
|
||||||
|
|
||||||
|
|
@ -294,15 +290,13 @@ pub trait Router: Send + Sync + 'static {
|
||||||
.ok_or_else(|| RouterError::InvalidParams("Missing arguments object".into()))?;
|
.ok_or_else(|| RouterError::InvalidParams("Missing arguments object".into()))?;
|
||||||
|
|
||||||
// Fetch the prompt definition first
|
// Fetch the prompt definition first
|
||||||
let prompt = match self.list_prompts() {
|
let prompt = self
|
||||||
Some(prompts) => prompts
|
.list_prompts()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|p| p.name == prompt_name)
|
.find(|p| p.name == prompt_name)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
RouterError::PromptNotFound(format!("Prompt '{}' not found", prompt_name))
|
RouterError::PromptNotFound(format!("Prompt '{}' not found", prompt_name))
|
||||||
})?,
|
})?;
|
||||||
None => return Err(RouterError::PromptNotFound("No prompts available".into())),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Validate required arguments
|
// Validate required arguments
|
||||||
if let Some(args) = &prompt.arguments {
|
if let Some(args) = &prompt.arguments {
|
||||||
|
|
@ -326,7 +320,6 @@ pub trait Router: Send + Sync + 'static {
|
||||||
// Now get the prompt content
|
// Now get the prompt content
|
||||||
let description = self
|
let description = self
|
||||||
.get_prompt(prompt_name)
|
.get_prompt(prompt_name)
|
||||||
.ok_or_else(|| RouterError::PromptNotFound("Prompt not found".into()))?
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| RouterError::Internal(e.to_string()))?;
|
.map_err(|e| RouterError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue