(
&mut self,
name: String,
arguments: Option<Vec<String>>,
)
| 1045 | } |
| 1046 | |
| 1047 | pub async fn get_prompt( |
| 1048 | &mut self, |
| 1049 | name: String, |
| 1050 | arguments: Option<Vec<String>>, |
| 1051 | ) -> Result<GetPromptResult, GetPromptError> { |
| 1052 | let (server_name, prompt_name) = match name.split_once('/') { |
| 1053 | None => (None::<String>, Some(name.clone())), |
| 1054 | Some((server_name, prompt_name)) => (Some(server_name.to_string()), Some(prompt_name.to_string())), |
| 1055 | }; |
| 1056 | let prompt_name = prompt_name.ok_or(GetPromptError::MissingPromptName)?; |
| 1057 | |
| 1058 | if let Some((query_sender, query_result_receiver)) = &self.prompts_sender_receiver_pair { |
| 1059 | query_sender |
| 1060 | .send(PromptQuery::List) |
| 1061 | .map_err(|e| GetPromptError::General(eyre::eyre!(e)))?; |
| 1062 | let prompts = query_result_receiver |
| 1063 | .resubscribe() |
| 1064 | .recv() |
| 1065 | .await |
| 1066 | .map_err(|e| GetPromptError::General(eyre::eyre!(e)))?; |
| 1067 | let PromptQueryResult::List(prompts) = prompts else { |
| 1068 | return Err(GetPromptError::IncorrectResponseType); |
| 1069 | }; |
| 1070 | |
| 1071 | match (prompts.get(&prompt_name), server_name.as_ref()) { |
| 1072 | // If we have more than one eligible clients but no server name specified |
| 1073 | (Some(bundles), None) if bundles.len() > 1 => { |
| 1074 | Err(GetPromptError::AmbiguousPrompt(prompt_name.clone(), { |
| 1075 | bundles.iter().fold("\n".to_string(), |mut acc, b| { |
| 1076 | acc.push_str(&format!("- @{}/{}\n", b.server_name, prompt_name)); |
| 1077 | acc |
| 1078 | }) |
| 1079 | })) |
| 1080 | }, |
| 1081 | // Normal case where we have enough info to proceed |
| 1082 | // Note that if bundle exists, it should never be empty |
| 1083 | (Some(bundles), sn) => { |
| 1084 | let bundle = if bundles.len() > 1 { |
| 1085 | let Some(sn) = sn else { |
| 1086 | return Err(GetPromptError::AmbiguousPrompt(prompt_name.clone(), { |
| 1087 | bundles.iter().fold("\n".to_string(), |mut acc, b| { |
| 1088 | acc.push_str(&format!("- @{}/{}\n", b.server_name, prompt_name)); |
| 1089 | acc |
| 1090 | }) |
| 1091 | })); |
| 1092 | }; |
| 1093 | let bundle = bundles.iter().find(|b| b.server_name == *sn); |
| 1094 | match bundle { |
| 1095 | Some(bundle) => bundle, |
| 1096 | None => { |
| 1097 | return Err(GetPromptError::AmbiguousPrompt(prompt_name.clone(), { |
| 1098 | bundles.iter().fold("\n".to_string(), |mut acc, b| { |
| 1099 | acc.push_str(&format!("- @{}/{}\n", b.server_name, prompt_name)); |
| 1100 | acc |
| 1101 | }) |
| 1102 | })); |
| 1103 | }, |
| 1104 | } |
no test coverage detected