mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-24 23:10:39 +08:00
fix(sessions): strip OpenClaw message_id suffix and allow 2-line titles
OpenClaw gateway injects `[message_id: UUID]` metadata at the end of every message, wasting display space. Strip this suffix from both title and summary fields. Also change session title display from single-line truncate to line-clamp-2, so longer titles (e.g. OpenClaw's timestamp-prefixed messages) can show more meaningful content across two lines.
This commit is contained in:
@@ -18,6 +18,15 @@ use super::utils::{
|
||||
|
||||
const PROVIDER_ID: &str = "openclaw";
|
||||
|
||||
/// Strip trailing `\n[message_id: ...]` metadata injected by OpenClaw gateway.
|
||||
fn strip_message_id_suffix(text: &str) -> &str {
|
||||
if let Some(pos) = text.rfind("\n[message_id:") {
|
||||
text[..pos].trim_end()
|
||||
} else {
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scan_sessions() -> Vec<SessionMeta> {
|
||||
let agents_dir = get_openclaw_dir().join("agents");
|
||||
if !agents_dir.exists() {
|
||||
@@ -215,14 +224,15 @@ fn parse_session(path: &Path, display_names: Option<&HashMap<String, String>>) -
|
||||
if event_type == "message" {
|
||||
if let Some(message) = value.get("message") {
|
||||
let text = message.get("content").map(extract_text).unwrap_or_default();
|
||||
if !text.trim().is_empty() {
|
||||
let cleaned = strip_message_id_suffix(&text);
|
||||
if !cleaned.trim().is_empty() {
|
||||
if first_user_message.is_none()
|
||||
&& message.get("role").and_then(Value::as_str) == Some("user")
|
||||
{
|
||||
first_user_message = Some(text.trim().to_string());
|
||||
first_user_message = Some(cleaned.trim().to_string());
|
||||
}
|
||||
if summary.is_none() {
|
||||
summary = Some(text);
|
||||
summary = Some(cleaned.trim().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export function SessionItem({
|
||||
{getProviderLabel(session.providerId, t)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<span className="text-sm font-medium truncate flex-1">
|
||||
<span className="text-sm font-medium line-clamp-2 flex-1">
|
||||
{searchQuery ? highlightText(title, searchQuery) : title}
|
||||
</span>
|
||||
<ChevronRight
|
||||
|
||||
Reference in New Issue
Block a user