mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
## What - Consume plaintext `output` from standalone search while retaining optional `encrypted_output` parsing. - Expose `web.run` to code mode and return search output to nested JavaScript calls. - Cover direct and code-mode standalone search paths with integration tests. ## Why `/v1/alpha/search` now returns plaintext output, which code mode needs to consume standalone search results. ## Test plan - `just test -p codex-api` - `just test -p codex-web-search-extension` - `just test -p codex-core code_mode_can_call_standalone_web_search` - `just test -p codex-app-server standalone_web_search_round_trips_output`
73 lines
2.1 KiB
Rust
73 lines
2.1 KiB
Rust
use codex_extension_api::ToolOutput;
|
|
use codex_extension_api::ToolPayload;
|
|
use codex_protocol::models::FunctionCallOutputContentItem;
|
|
use codex_protocol::models::FunctionCallOutputPayload;
|
|
use codex_protocol::models::ResponseInputItem;
|
|
|
|
pub(crate) struct SearchOutput {
|
|
output: String,
|
|
}
|
|
|
|
impl SearchOutput {
|
|
pub(crate) fn new(output: String) -> Self {
|
|
Self { output }
|
|
}
|
|
}
|
|
|
|
impl ToolOutput for SearchOutput {
|
|
fn log_preview(&self) -> String {
|
|
"[standalone web search output]".to_string()
|
|
}
|
|
|
|
fn success_for_logging(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
fn to_response_item(&self, call_id: &str, _payload: &ToolPayload) -> ResponseInputItem {
|
|
// TODO: Make standalone search honor memories.disable_on_external_context,
|
|
// as hosted web search does.
|
|
ResponseInputItem::FunctionCallOutput {
|
|
call_id: call_id.to_string(),
|
|
output: FunctionCallOutputPayload::from_content_items(vec![
|
|
FunctionCallOutputContentItem::InputText {
|
|
text: self.output.clone(),
|
|
},
|
|
]),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use codex_extension_api::ToolPayload;
|
|
use codex_protocol::models::FunctionCallOutputContentItem;
|
|
use codex_protocol::models::FunctionCallOutputPayload;
|
|
use codex_protocol::models::ResponseInputItem;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use super::SearchOutput;
|
|
use super::ToolOutput;
|
|
|
|
#[test]
|
|
fn emits_plaintext_function_call_output() {
|
|
let output = SearchOutput::new("search output".to_string());
|
|
|
|
assert_eq!(
|
|
output.to_response_item(
|
|
"call-1",
|
|
&ToolPayload::Function {
|
|
arguments: "{}".to_string(),
|
|
},
|
|
),
|
|
ResponseInputItem::FunctionCallOutput {
|
|
call_id: "call-1".to_string(),
|
|
output: FunctionCallOutputPayload::from_content_items(vec![
|
|
FunctionCallOutputContentItem::InputText {
|
|
text: "search output".to_string(),
|
|
},
|
|
]),
|
|
}
|
|
);
|
|
}
|
|
}
|