mirror of
https://github.com/openai/codex.git
synced 2026-02-01 22:47:52 +00:00
Factor
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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}"
|
||||
))
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user