feat: show conversation content in usage logs

This commit is contained in:
boos
2026-06-06 19:36:42 +08:00
parent ef0f91e683
commit cd843465b2
10 changed files with 566 additions and 70 deletions
+33 -2
View File
@@ -63,7 +63,19 @@ async fn user_picture_log_items_limited(
"pending" => "pending",
_ => "running",
};
json!({
let content_summary = result
.get("prompt")
.and_then(Value::as_str)
.or_else(|| result.get("input").and_then(Value::as_str))
.or_else(|| result.get("message").and_then(Value::as_str))
.map(|text| text.chars().take(240).collect::<String>());
let request_content = result
.get("prompt")
.and_then(Value::as_str)
.or_else(|| result.get("input").and_then(Value::as_str))
.or_else(|| result.get("message").and_then(Value::as_str))
.map(str::to_string);
let mut item = json!({
"id": task.id,
"route_id": Value::Null,
"channel_id": Value::Null,
@@ -103,7 +115,19 @@ async fn user_picture_log_items_limited(
"progress_total": task.progress_total,
"status_label": status,
"result": result,
})
});
if let Some(object) = item.as_object_mut() {
object.insert(
"content_summary".to_string(),
content_summary.map(Value::String).unwrap_or(Value::Null),
);
object.insert(
"request_content".to_string(),
request_content.map(Value::String).unwrap_or(Value::Null),
);
object.insert("response_content".to_string(), Value::Null);
}
item
})
.collect())
}
@@ -181,6 +205,9 @@ async fn user_usage_log_items_limited(
"client_app_id": "picture-agent",
"client_app_name": "Picture Agent",
"client_confidence": "high",
"content_summary": Value::Null,
"request_content": Value::Null,
"response_content": Value::Null,
"created_at": row.try_get::<Option<String>, _>("created_at").ok().flatten(),
"source": "usage-logs",
"task_type": "usage-log",
@@ -202,6 +229,9 @@ fn user_log_text(item: &Value) -> String {
item.get("site_name").and_then(Value::as_str),
item.get("site_url").and_then(Value::as_str),
item.get("error_message").and_then(Value::as_str),
item.get("content_summary").and_then(Value::as_str),
item.get("request_content").and_then(Value::as_str),
item.get("response_content").and_then(Value::as_str),
item.get("message").and_then(Value::as_str),
item.get("title").and_then(Value::as_str),
item.get("source").and_then(Value::as_str),
@@ -315,6 +345,7 @@ async fn load_user_log_items_limited(
l.prompt_tokens, l.completion_tokens, l.total_tokens, l.estimated_cost,
l.error_message, l.retry_count, l.is_stream,
l.client_family, l.client_app_id, l.client_app_name, l.client_confidence,
l.content_summary, l.request_content, l.response_content,
l.created_at,
a.site_id AS site_id,
COALESCE(NULLIF(a.username, ''), CASE WHEN a.id IS NULL THEN NULL ELSE '账号 #' || a.id END) AS username,