mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
Clippy
This commit is contained in:
@@ -109,9 +109,7 @@ pub async fn process_sse_wire<S, D>(
|
||||
|
||||
fn next_frame(buffer: &mut String) -> Option<String> {
|
||||
loop {
|
||||
let Some(idx) = buffer.find("\n\n") else {
|
||||
return None;
|
||||
};
|
||||
let idx = buffer.find("\n\n")?;
|
||||
|
||||
let frame = buffer[..idx].to_string();
|
||||
buffer.drain(..idx + 2);
|
||||
|
||||
@@ -48,7 +48,7 @@ impl WireResponseDecoder for WireResponsesSseDecoder {
|
||||
if let Some(delta) = event.delta.or_else(|| {
|
||||
event.item.and_then(|v| {
|
||||
v.get("delta")
|
||||
.and_then(|d| d.as_str().map(|s| s.to_string()))
|
||||
.and_then(|d| d.as_str().map(std::string::ToString::to_string))
|
||||
})
|
||||
}) {
|
||||
let _ = tx.send(Ok(WireEvent::OutputTextDelta(delta))).await;
|
||||
@@ -110,7 +110,7 @@ impl WireResponseDecoder for WireResponsesSseDecoder {
|
||||
.as_ref()
|
||||
.and_then(|v| v.get("message"))
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string())
|
||||
.map(std::string::ToString::to_string)
|
||||
.unwrap_or_else(|| "unknown error".to_string());
|
||||
let _ = tx.send(Err(Error::Stream(message, None))).await;
|
||||
}
|
||||
@@ -125,35 +125,35 @@ fn parse_wire_usage(resp: &Value) -> Option<WireTokenUsage> {
|
||||
let usage = resp.get("usage").cloned()?;
|
||||
let input_tokens = usage
|
||||
.get("input_tokens")
|
||||
.and_then(|v| v.as_i64())
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
.unwrap_or(0);
|
||||
let cached_input_tokens = usage
|
||||
.get("cached_input_tokens")
|
||||
.and_then(|v| v.as_i64())
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
.or_else(|| {
|
||||
usage
|
||||
.get("input_tokens_details")
|
||||
.and_then(|d| d.get("cached_tokens"))
|
||||
.and_then(|v| v.as_i64())
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
})
|
||||
.unwrap_or(0);
|
||||
let output_tokens = usage
|
||||
.get("output_tokens")
|
||||
.and_then(|v| v.as_i64())
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
.unwrap_or(0);
|
||||
let reasoning_output_tokens = usage
|
||||
.get("reasoning_output_tokens")
|
||||
.and_then(|v| v.as_i64())
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
.or_else(|| {
|
||||
usage
|
||||
.get("output_tokens_details")
|
||||
.and_then(|d| d.get("reasoning_tokens"))
|
||||
.and_then(|v| v.as_i64())
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
})
|
||||
.unwrap_or(0);
|
||||
let total_tokens = usage
|
||||
.get("total_tokens")
|
||||
.and_then(|v| v.as_i64())
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
.unwrap_or(0);
|
||||
|
||||
Some(WireTokenUsage {
|
||||
|
||||
@@ -298,7 +298,7 @@ fn wrap_wire_stream(stream: codex_api_client::WireResponseStream) -> ResponseStr
|
||||
tokio::spawn(async move {
|
||||
let mut stream = stream;
|
||||
while let Some(item) = stream.next().await {
|
||||
let mapped = item.map(|ev| map_wire_event(ev)).map_err(map_api_error);
|
||||
let mapped = item.map(map_wire_event).map_err(map_api_error);
|
||||
if tx.send(mapped).await.is_err() {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user