This commit is contained in:
Charles Cunningham
2026-01-30 19:57:30 -08:00
parent e9b2bc41e3
commit 6b65d7c77b
3 changed files with 28 additions and 12 deletions

View File

@@ -1693,23 +1693,16 @@ impl Session {
return;
}
let call_id = call_id.unwrap_or_else(|| sub_id.to_string());
let content = match serde_json::to_string(&response) {
Ok(content) => content,
let call_id_for_log = call_id.clone();
let response_item = match response.to_function_call_output(call_id) {
Ok(item) => item,
Err(err) => {
warn!(
"failed to serialize request_user_input response for call_id: {call_id}: {err}"
"failed to serialize request_user_input response for call_id: {call_id_for_log}: {err}"
);
return;
}
};
let response_item = ResponseItem::FunctionCallOutput {
call_id,
output: FunctionCallOutputPayload {
content,
success: Some(true),
..Default::default()
},
};
let turn_context = self.new_default_turn_with_sub_id(sub_id.to_string()).await;
self.record_conversation_items(&turn_context, &[response_item])
.await;

View File

@@ -71,7 +71,7 @@ impl ToolHandler for RequestUserInputHandler {
)
})?;
let content = serde_json::to_string(&response).map_err(|err| {
let content = response.to_output_content().map_err(|err| {
FunctionCallError::Fatal(format!(
"failed to serialize request_user_input response: {err}"
))

View File

@@ -1,5 +1,7 @@
use std::collections::HashMap;
use crate::models::FunctionCallOutputPayload;
use crate::models::ResponseItem;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
@@ -48,6 +50,27 @@ pub struct RequestUserInputResponse {
pub interrupted: bool,
}
impl RequestUserInputResponse {
pub fn to_output_content(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(self)
}
pub fn to_function_call_output(
&self,
call_id: String,
) -> Result<ResponseItem, serde_json::Error> {
let content = self.to_output_content()?;
Ok(ResponseItem::FunctionCallOutput {
call_id,
output: FunctionCallOutputPayload {
content,
success: Some(true),
..Default::default()
},
})
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
pub struct RequestUserInputEvent {
/// Responses API call id for the associated tool call, if available.