Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions src/OpenClaw.Shared/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,6 @@ private static bool TryGetBool(JsonElement parent, string property) =>
}
}

public sealed class SessionPresentationInfo
{
public string Title { get; set; } = "";
public string TitleSource { get; set; } = "generated";
public string? Subtitle { get; set; }
public string Family { get; set; } = "custom";
public string? AgentId { get; set; }
public string? Channel { get; set; }
public string? AccountId { get; set; }
public string? PeerKind { get; set; }
public bool IsMain { get; set; }
public bool IsBackground { get; set; }
}

public sealed class SessionWorktreeInfo
{
public string? Id { get; set; }
Expand All @@ -279,14 +265,6 @@ public class SessionInfo
public SessionInfo Clone()
{
var copy = (SessionInfo)MemberwiseClone();
if (copy.Presentation is { } p)
copy.Presentation = new SessionPresentationInfo
{
Title = p.Title, TitleSource = p.TitleSource, Subtitle = p.Subtitle,
Family = p.Family, AgentId = p.AgentId, Channel = p.Channel,
AccountId = p.AccountId, PeerKind = p.PeerKind,
IsMain = p.IsMain, IsBackground = p.IsBackground,
};
if (copy.Worktree is { } w)
copy.Worktree = new SessionWorktreeInfo
{
Expand All @@ -309,12 +287,16 @@ public SessionInfo Clone()
public string? Room { get; set; }
public string? Space { get; set; }
public string? ChatType { get; set; }
public string? Classification { get; set; }
public string? AgentId { get; set; }
public string? AccountId { get; set; }
public string? PeerKind { get; set; }
public bool? IsBackground { get; set; }
public string? OriginLabel { get; set; }
public SessionWorktreeInfo? Worktree { get; set; }
public string? ExecNode { get; set; }
public string? ParentSessionKey { get; set; }
public int? SpawnDepth { get; set; }
public SessionPresentationInfo? Presentation { get; set; }
public string? SessionId { get; set; }
public string? ThinkingLevel { get; set; }
public string? VerboseLevel { get; set; }
Expand Down Expand Up @@ -352,7 +334,7 @@ public string RichDisplayText
{
get
{
var title = SessionPresentationResolver.Resolve(this).Title;
var title = SessionDisplayResolver.Resolve(this).Title;

// Fixed-size array avoids List<string> allocation; at most 9 detail slots.
var details = new string?[9];
Expand Down Expand Up @@ -395,7 +377,7 @@ public string ContextSummaryShort
/// <summary>Gets a shortened, user-friendly version of the session key.</summary>
public string ShortKey
{
get => SessionPresentationResolver.Resolve(this).Title;
get => SessionDisplayResolver.Resolve(this).Title;
}

}
Expand Down
60 changes: 7 additions & 53 deletions src/OpenClaw.Shared/OpenClawGatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3792,16 +3792,6 @@ private void UpdateSessionMainStatus(SessionInfo session, string sessionKey, Jso
return;
}

if (item.ValueKind == JsonValueKind.Object
&& item.TryGetProperty("presentation", out var presentation)
&& presentation.ValueKind == JsonValueKind.Object
&& TryGetRequiredBoolean(presentation, "isMain", out var presentationIsMain))
{
session.IsMain = presentationIsMain;
session.IsMainResolved = true;
return;
}

if (item.ValueKind == JsonValueKind.Object
&& item.TryGetProperty("isMain", out var isMain)
&& isMain.ValueKind is JsonValueKind.True or JsonValueKind.False)
Expand Down Expand Up @@ -3846,6 +3836,13 @@ private void PopulateSessionFromObject(SessionInfo session, JsonElement item)
session.Room = GetString(item, "room");
if (item.TryGetProperty("space", out _)) session.Space = GetString(item, "space");
if (item.TryGetProperty("chatType", out _)) session.ChatType = GetString(item, "chatType");
if (item.TryGetProperty("classification", out _)) session.Classification = GetString(item, "classification");
if (item.TryGetProperty("agentId", out _)) session.AgentId = GetString(item, "agentId");
if (item.TryGetProperty("accountId", out _)) session.AccountId = GetString(item, "accountId");
if (item.TryGetProperty("peerKind", out _)) session.PeerKind = GetString(item, "peerKind");
if (item.TryGetProperty("isBackground", out var isBackground)
&& isBackground.ValueKind is JsonValueKind.True or JsonValueKind.False)
session.IsBackground = isBackground.GetBoolean();
if (item.TryGetProperty("execNode", out _)) session.ExecNode = GetString(item, "execNode");
if (item.TryGetProperty("parentSessionKey", out _))
session.ParentSessionKey = GetString(item, "parentSessionKey");
Expand All @@ -3859,12 +3856,6 @@ private void PopulateSessionFromObject(SessionInfo session, JsonElement item)
? GetString(origin, "label")
: null;
if (item.TryGetProperty("worktree", out _)) session.Worktree = ParseSessionWorktree(item);
if (item.TryGetProperty("presentation", out _))
session.Presentation = ParseSessionPresentation(item);
if (session.Presentation is { } presentation)
{
session.Channel ??= presentation.Channel;
}
if (item.TryGetProperty("sessionId", out var sessionId))
session.SessionId = sessionId.GetString();
if (item.TryGetProperty("thinkingLevel", out var thinking))
Expand Down Expand Up @@ -3916,43 +3907,6 @@ private void PopulateSessionFromObject(SessionInfo session, JsonElement item)
: new SessionWorktreeInfo { Id = id, Branch = branch, RepoRoot = repoRoot };
}

private static SessionPresentationInfo? ParseSessionPresentation(JsonElement item)
{
if (!item.TryGetProperty("presentation", out var presentation)
|| presentation.ValueKind != JsonValueKind.Object)
return null;

var title = GetString(presentation, "title");
var family = GetString(presentation, "family");
if (title is null
|| family is null
|| !TryGetRequiredBoolean(presentation, "isMain", out var isMain)
|| !TryGetRequiredBoolean(presentation, "isBackground", out var isBackground))
return null;

return new SessionPresentationInfo
{
Title = title,
TitleSource = GetString(presentation, "titleSource") ?? "generated",
Subtitle = GetString(presentation, "subtitle"),
Family = family,
AgentId = GetString(presentation, "agentId"),
Channel = GetString(presentation, "channel"),
AccountId = GetString(presentation, "accountId"),
PeerKind = GetString(presentation, "peerKind"),
IsMain = isMain,
IsBackground = isBackground,
};
}

private static bool TryGetRequiredBoolean(JsonElement parent, string propertyName, out bool value)
{
value = false;
if (!parent.TryGetProperty(propertyName, out var property)) return false;
if (property.ValueKind == JsonValueKind.True) value = true;
return property.ValueKind is JsonValueKind.True or JsonValueKind.False;
}

private void ParseNodeList(JsonElement nodesPayload)
{
try
Expand Down
Loading
Loading