refactor: unify IntoCallToolResult Result impls (#787)
This commit is contained in:
parent
d98248ac22
commit
5891b45162
2 changed files with 17 additions and 29 deletions
|
|
@ -85,20 +85,29 @@ impl<T: IntoContents> IntoCallToolResult for T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: IntoContents, E: IntoContents> IntoCallToolResult for Result<T, E> {
|
impl IntoCallToolResult for CallToolResult {
|
||||||
fn into_call_tool_result(self) -> Result<CallToolResult, crate::ErrorData> {
|
fn into_call_tool_result(self) -> Result<CallToolResult, crate::ErrorData> {
|
||||||
match self {
|
Ok(self)
|
||||||
Ok(value) => Ok(CallToolResult::success(value.into_contents())),
|
|
||||||
Err(error) => Ok(CallToolResult::error(error.into_contents())),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: IntoCallToolResult> IntoCallToolResult for Result<T, crate::ErrorData> {
|
impl IntoCallToolResult for crate::ErrorData {
|
||||||
|
fn into_call_tool_result(self) -> Result<CallToolResult, crate::ErrorData> {
|
||||||
|
Err(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: IntoCallToolResult, E: IntoCallToolResult> IntoCallToolResult for Result<T, E> {
|
||||||
fn into_call_tool_result(self) -> Result<CallToolResult, crate::ErrorData> {
|
fn into_call_tool_result(self) -> Result<CallToolResult, crate::ErrorData> {
|
||||||
match self {
|
match self {
|
||||||
Ok(value) => value.into_call_tool_result(),
|
Ok(value) => value.into_call_tool_result(),
|
||||||
Err(error) => Err(error),
|
Err(error) => match error.into_call_tool_result() {
|
||||||
|
Ok(mut result) => {
|
||||||
|
result.is_error = Some(true);
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
Err(e) => Err(e),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,12 +148,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoCallToolResult for Result<CallToolResult, crate::ErrorData> {
|
|
||||||
fn into_call_tool_result(self) -> Result<CallToolResult, crate::ErrorData> {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait CallToolHandler<S, A> {
|
pub trait CallToolHandler<S, A> {
|
||||||
fn call(
|
fn call(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@ use std::borrow::Cow;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{handler::server::tool::IntoCallToolResult, model::CallToolResult};
|
||||||
handler::server::tool::IntoCallToolResult,
|
|
||||||
model::{CallToolResult, IntoContents},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Json wrapper for structured output
|
/// Json wrapper for structured output
|
||||||
///
|
///
|
||||||
|
|
@ -41,15 +38,3 @@ impl<T: Serialize + JsonSchema + 'static> IntoCallToolResult for Json<T> {
|
||||||
Ok(CallToolResult::structured(value))
|
Ok(CallToolResult::structured(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation for Result<Json<T>, E>
|
|
||||||
impl<T: Serialize + JsonSchema + 'static, E: IntoContents> IntoCallToolResult
|
|
||||||
for Result<Json<T>, E>
|
|
||||||
{
|
|
||||||
fn into_call_tool_result(self) -> Result<CallToolResult, crate::ErrorData> {
|
|
||||||
match self {
|
|
||||||
Ok(value) => value.into_call_tool_result(),
|
|
||||||
Err(error) => Ok(CallToolResult::error(error.into_contents())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue