Skip to content

Commit 2341450

Browse files
RomneyDabkudiessCopilot
authored
feat(sessions): consume flattened gateway classification (#1069)
* feat(sessions): consume flattened gateway classification * test(sessions): fix flattened facts test syntax * fix(sessions): preserve legacy display fallback * fix(sessions): reject raw key display names Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: [email protected] <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent d2de615 commit 2341450

17 files changed

Lines changed: 396 additions & 761 deletions

‎src/OpenClaw.Shared/Models.cs‎

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,6 @@ private static bool TryGetBool(JsonElement parent, string property) =>
251251
}
252252
}
253253

254-
public sealed class SessionPresentationInfo
255-
{
256-
public string Title { get; set; } = "";
257-
public string TitleSource { get; set; } = "generated";
258-
public string? Subtitle { get; set; }
259-
public string Family { get; set; } = "custom";
260-
public string? AgentId { get; set; }
261-
public string? Channel { get; set; }
262-
public string? AccountId { get; set; }
263-
public string? PeerKind { get; set; }
264-
public bool IsMain { get; set; }
265-
public bool IsBackground { get; set; }
266-
}
267-
268254
public sealed class SessionWorktreeInfo
269255
{
270256
public string? Id { get; set; }
@@ -279,14 +265,6 @@ public class SessionInfo
279265
public SessionInfo Clone()
280266
{
281267
var copy = (SessionInfo)MemberwiseClone();
282-
if (copy.Presentation is { } p)
283-
copy.Presentation = new SessionPresentationInfo
284-
{
285-
Title = p.Title, TitleSource = p.TitleSource, Subtitle = p.Subtitle,
286-
Family = p.Family, AgentId = p.AgentId, Channel = p.Channel,
287-
AccountId = p.AccountId, PeerKind = p.PeerKind,
288-
IsMain = p.IsMain, IsBackground = p.IsBackground,
289-
};
290268
if (copy.Worktree is { } w)
291269
copy.Worktree = new SessionWorktreeInfo
292270
{
@@ -309,12 +287,16 @@ public SessionInfo Clone()
309287
public string? Room { get; set; }
310288
public string? Space { get; set; }
311289
public string? ChatType { get; set; }
290+
public string? Classification { get; set; }
291+
public string? AgentId { get; set; }
292+
public string? AccountId { get; set; }
293+
public string? PeerKind { get; set; }
294+
public bool? IsBackground { get; set; }
312295
public string? OriginLabel { get; set; }
313296
public SessionWorktreeInfo? Worktree { get; set; }
314297
public string? ExecNode { get; set; }
315298
public string? ParentSessionKey { get; set; }
316299
public int? SpawnDepth { get; set; }
317-
public SessionPresentationInfo? Presentation { get; set; }
318300
public string? SessionId { get; set; }
319301
public string? ThinkingLevel { get; set; }
320302
public string? VerboseLevel { get; set; }
@@ -352,7 +334,7 @@ public string RichDisplayText
352334
{
353335
get
354336
{
355-
var title = SessionPresentationResolver.Resolve(this).Title;
337+
var title = SessionDisplayResolver.Resolve(this).Title;
356338

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

401383
}

‎src/OpenClaw.Shared/OpenClawGatewayClient.cs‎

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,16 +3792,6 @@ private void UpdateSessionMainStatus(SessionInfo session, string sessionKey, Jso
37923792
return;
37933793
}
37943794

3795-
if (item.ValueKind == JsonValueKind.Object
3796-
&& item.TryGetProperty("presentation", out var presentation)
3797-
&& presentation.ValueKind == JsonValueKind.Object
3798-
&& TryGetRequiredBoolean(presentation, "isMain", out var presentationIsMain))
3799-
{
3800-
session.IsMain = presentationIsMain;
3801-
session.IsMainResolved = true;
3802-
return;
3803-
}
3804-
38053795
if (item.ValueKind == JsonValueKind.Object
38063796
&& item.TryGetProperty("isMain", out var isMain)
38073797
&& isMain.ValueKind is JsonValueKind.True or JsonValueKind.False)
@@ -3846,6 +3836,13 @@ private void PopulateSessionFromObject(SessionInfo session, JsonElement item)
38463836
session.Room = GetString(item, "room");
38473837
if (item.TryGetProperty("space", out _)) session.Space = GetString(item, "space");
38483838
if (item.TryGetProperty("chatType", out _)) session.ChatType = GetString(item, "chatType");
3839+
if (item.TryGetProperty("classification", out _)) session.Classification = GetString(item, "classification");
3840+
if (item.TryGetProperty("agentId", out _)) session.AgentId = GetString(item, "agentId");
3841+
if (item.TryGetProperty("accountId", out _)) session.AccountId = GetString(item, "accountId");
3842+
if (item.TryGetProperty("peerKind", out _)) session.PeerKind = GetString(item, "peerKind");
3843+
if (item.TryGetProperty("isBackground", out var isBackground)
3844+
&& isBackground.ValueKind is JsonValueKind.True or JsonValueKind.False)
3845+
session.IsBackground = isBackground.GetBoolean();
38493846
if (item.TryGetProperty("execNode", out _)) session.ExecNode = GetString(item, "execNode");
38503847
if (item.TryGetProperty("parentSessionKey", out _))
38513848
session.ParentSessionKey = GetString(item, "parentSessionKey");
@@ -3859,12 +3856,6 @@ private void PopulateSessionFromObject(SessionInfo session, JsonElement item)
38593856
? GetString(origin, "label")
38603857
: null;
38613858
if (item.TryGetProperty("worktree", out _)) session.Worktree = ParseSessionWorktree(item);
3862-
if (item.TryGetProperty("presentation", out _))
3863-
session.Presentation = ParseSessionPresentation(item);
3864-
if (session.Presentation is { } presentation)
3865-
{
3866-
session.Channel ??= presentation.Channel;
3867-
}
38683859
if (item.TryGetProperty("sessionId", out var sessionId))
38693860
session.SessionId = sessionId.GetString();
38703861
if (item.TryGetProperty("thinkingLevel", out var thinking))
@@ -3916,43 +3907,6 @@ private void PopulateSessionFromObject(SessionInfo session, JsonElement item)
39163907
: new SessionWorktreeInfo { Id = id, Branch = branch, RepoRoot = repoRoot };
39173908
}
39183909

3919-
private static SessionPresentationInfo? ParseSessionPresentation(JsonElement item)
3920-
{
3921-
if (!item.TryGetProperty("presentation", out var presentation)
3922-
|| presentation.ValueKind != JsonValueKind.Object)
3923-
return null;
3924-
3925-
var title = GetString(presentation, "title");
3926-
var family = GetString(presentation, "family");
3927-
if (title is null
3928-
|| family is null
3929-
|| !TryGetRequiredBoolean(presentation, "isMain", out var isMain)
3930-
|| !TryGetRequiredBoolean(presentation, "isBackground", out var isBackground))
3931-
return null;
3932-
3933-
return new SessionPresentationInfo
3934-
{
3935-
Title = title,
3936-
TitleSource = GetString(presentation, "titleSource") ?? "generated",
3937-
Subtitle = GetString(presentation, "subtitle"),
3938-
Family = family,
3939-
AgentId = GetString(presentation, "agentId"),
3940-
Channel = GetString(presentation, "channel"),
3941-
AccountId = GetString(presentation, "accountId"),
3942-
PeerKind = GetString(presentation, "peerKind"),
3943-
IsMain = isMain,
3944-
IsBackground = isBackground,
3945-
};
3946-
}
3947-
3948-
private static bool TryGetRequiredBoolean(JsonElement parent, string propertyName, out bool value)
3949-
{
3950-
value = false;
3951-
if (!parent.TryGetProperty(propertyName, out var property)) return false;
3952-
if (property.ValueKind == JsonValueKind.True) value = true;
3953-
return property.ValueKind is JsonValueKind.True or JsonValueKind.False;
3954-
}
3955-
39563910
private void ParseNodeList(JsonElement nodesPayload)
39573911
{
39583912
try

0 commit comments

Comments
 (0)