Kill Reasoning, Debug, Activity variants — read status from Agent directly
Reasoning tokens: dropped for now, will land in context entries later. Debug sends: converted to dbglog! macro (writes to debug.log). Activity: now a field on Agent, set directly, read by UI via try_lock. score_memories_incremental takes agent Arc for activity writes. UiMessage down to 2 variants: TextDelta, Info. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
eafc2887a3
commit
e7914e3d58
7 changed files with 54 additions and 88 deletions
|
|
@ -130,7 +130,7 @@ impl ApiClient {
|
|||
&reasoning_effort, sampling, priority,
|
||||
).await;
|
||||
if let Err(e) = result {
|
||||
let _ = tx.send(StreamEvent::Error(e.to_string()));
|
||||
let _ = tx.send(StreamEvent::Error(e.to_string();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -218,10 +218,10 @@ pub(crate) async fn send_and_check(
|
|||
let payload_size = serde_json::to_string(body)
|
||||
.map(|s| s.len())
|
||||
.unwrap_or(0);
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"request: {}K payload, {}",
|
||||
payload_size / 1024, debug_label,
|
||||
)));
|
||||
);
|
||||
}
|
||||
|
||||
let mut req = client
|
||||
|
|
@ -262,24 +262,24 @@ pub(crate) async fn send_and_check(
|
|||
"x-request-id",
|
||||
] {
|
||||
if let Some(val) = headers.get(name) {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"header {}: {}",
|
||||
name,
|
||||
val.to_str().unwrap_or("?")
|
||||
)));
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !status.is_success() {
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"HTTP {} after {:.1}s ({}): {}",
|
||||
status,
|
||||
elapsed.as_secs_f64(),
|
||||
url,
|
||||
&body[..body.len().min(500)]
|
||||
)));
|
||||
);
|
||||
if let Some(json) = request_json {
|
||||
let log_dir = dirs::home_dir()
|
||||
.unwrap_or_default()
|
||||
|
|
@ -288,20 +288,20 @@ pub(crate) async fn send_and_check(
|
|||
let ts = chrono::Local::now().format("%Y%m%dT%H%M%S");
|
||||
let path = log_dir.join(format!("{}.json", ts));
|
||||
if std::fs::write(&path, json).is_ok() {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"saved failed request to {} (HTTP {})", path.display(), status
|
||||
)));
|
||||
);
|
||||
}
|
||||
}
|
||||
anyhow::bail!("HTTP {} ({}): {}", status, url, &body[..body.len().min(1000)]);
|
||||
}
|
||||
|
||||
if debug {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"connected in {:.1}s (HTTP {})",
|
||||
elapsed.as_secs_f64(),
|
||||
status.as_u16()
|
||||
)));
|
||||
);
|
||||
}
|
||||
|
||||
Ok(response)
|
||||
|
|
@ -353,9 +353,9 @@ impl SseReader {
|
|||
let ts = chrono::Local::now().format("%Y%m%dT%H%M%S");
|
||||
let path = log_dir.join(format!("{}.json", ts));
|
||||
if std::fs::write(&path, json).is_ok() {
|
||||
let _ = self.ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"saved failed request to {} ({})", path.display(), reason
|
||||
)));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -396,10 +396,10 @@ impl SseReader {
|
|||
} else {
|
||||
json_str.to_string()
|
||||
};
|
||||
let _ = self.ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"SSE parse error (#{}) {}: {}",
|
||||
self.sse_parse_errors, e, preview
|
||||
)));
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -431,7 +431,7 @@ impl SseReader {
|
|||
self.sse_lines_parsed,
|
||||
e, buf_preview,
|
||||
);
|
||||
let _ = self.ui_tx.send(UiMessage::Debug(msg.clone()));
|
||||
dbglog!("{}", msg);
|
||||
self.save_failed_request(&msg);
|
||||
return Err(e.into());
|
||||
}
|
||||
|
|
@ -450,7 +450,7 @@ impl SseReader {
|
|||
self.stream_start.elapsed().as_secs_f64(),
|
||||
buf_preview,
|
||||
);
|
||||
let _ = self.ui_tx.send(UiMessage::Debug(msg.clone()));
|
||||
dbglog!("{}", msg);
|
||||
self.save_failed_request(&msg);
|
||||
anyhow::bail!(
|
||||
"stream timeout: no data for {}s ({} chunks received)",
|
||||
|
|
@ -535,43 +535,43 @@ pub(crate) fn log_diagnostics(
|
|||
let debug = std::env::var("POC_DEBUG").is_ok();
|
||||
|
||||
if reasoning_chars > 0 && reasoning_effort == "none" {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"note: {} chars leaked reasoning (suppressed from display)",
|
||||
reasoning_chars
|
||||
)));
|
||||
);
|
||||
}
|
||||
if content_len == 0 && tool_count == 0 {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"WARNING: empty response (finish: {:?}, chunks: {}, reasoning: {}, \
|
||||
parse_errors: {}, empty_deltas: {}, {:.1}s)",
|
||||
finish_reason, chunks_received, reasoning_chars,
|
||||
sse_parse_errors, empty_deltas, total_elapsed.as_secs_f64()
|
||||
)));
|
||||
);
|
||||
}
|
||||
if finish_reason.is_none() && chunks_received > 0 {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"WARNING: stream ended without finish_reason ({} chunks, {} content chars)",
|
||||
chunks_received, content_len
|
||||
)));
|
||||
);
|
||||
}
|
||||
if sse_parse_errors > 0 {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"WARNING: {} SSE parse errors out of {} lines",
|
||||
sse_parse_errors, sse_lines_parsed
|
||||
)));
|
||||
);
|
||||
}
|
||||
|
||||
if debug {
|
||||
if let Some(u) = usage {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"tokens: {} prompt + {} completion = {} total",
|
||||
u.prompt_tokens, u.completion_tokens, u.total_tokens
|
||||
)));
|
||||
);
|
||||
}
|
||||
let ttft = first_content_at
|
||||
.map(|d| format!("{:.1}s", d.as_secs_f64()))
|
||||
.unwrap_or_else(|| "none".to_string());
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
"stream: {:.1}s total, TTFT={}, {} chunks, {} SSE lines, \
|
||||
{} content chars, {} reasoning chars, {} tools, \
|
||||
finish={:?}",
|
||||
|
|
@ -583,13 +583,13 @@ pub(crate) fn log_diagnostics(
|
|||
reasoning_chars,
|
||||
tool_count,
|
||||
finish_reason,
|
||||
)));
|
||||
);
|
||||
if !tools.is_empty() {
|
||||
for (i, tc) in tools.iter().enumerate() {
|
||||
let _ = ui_tx.send(UiMessage::Debug(format!(
|
||||
dbglog!(
|
||||
" tool[{}]: {} (id: {}, {} arg chars)",
|
||||
i, tc.function.name, tc.id, tc.function.arguments.len()
|
||||
)));
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -699,7 +699,8 @@ pub async fn collect_stream(
|
|||
}
|
||||
}
|
||||
StreamEvent::Reasoning(text) => {
|
||||
let _ = ui_tx.send(UiMessage::Reasoning(text));
|
||||
// TODO: reasoning tokens → context entries
|
||||
let _ = text;
|
||||
}
|
||||
StreamEvent::ToolCallDelta { index, id, call_type, name, arguments } => {
|
||||
while tool_calls.len() <= index {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue