Skip to content

Commit 08cab69

Browse files
authored
feat(chat): add native FunctionalUI chat experience
Adds the native WinUI chat experience using the in-repo OpenClawTray.FunctionalUI layer, without vendoring Reactor. Includes chat timeline/provider infrastructure, markdown sanitization, debug exploration surfaces, and tests. Maintainer follow-up fixes FunctionalUI effect cleanup and stale WebView credential navigation.\n\nCo-authored-by: Copilot <[email protected]>
1 parent a4f106c commit 08cab69

57 files changed

Lines changed: 12295 additions & 469 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎DEVELOPMENT.md‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ A comprehensive guide for building, running, and contributing to the OpenClaw Wi
3434

3535
## Project Structure
3636

37-
This monorepo contains three projects:
37+
This monorepo contains these main projects:
3838

3939
```
4040
openclaw-windows-hub/
@@ -44,6 +44,13 @@ openclaw-windows-hub/
4444
│ │ ├── Models.cs # Data models (SessionInfo, ChannelHealth, etc.)
4545
│ │ └── IOpenClawLogger.cs # Logging interface
4646
│ │
47+
│ ├── OpenClaw.Chat/ # Native chat model and reducer
48+
│ │ ├── ChatModels.cs # Threads, entries, events, provider contract
49+
│ │ └── ChatTimelineReducer.cs # Timeline state transitions
50+
│ │
51+
│ ├── OpenClawTray.FunctionalUI/ # Small in-repo declarative WinUI helper
52+
│ │ └── FunctionalUI.cs # Components, hooks, elements, host control
53+
│ │
4754
│ ├── OpenClaw.Tray.WinUI/ # WinUI 3 system tray application (primary)
4855
│ │ ├── App.xaml.cs # Main application, tray icon, gateway connection
4956
│ │ ├── Services/ # Settings, logging, hotkeys, deep links
@@ -220,6 +227,47 @@ This creates a standalone executable with all dependencies bundled.
220227

221228
## Architecture Overview
222229

230+
### Native chat surface (FunctionalUI + OpenClaw.Chat)
231+
232+
The Hub Chat tab (`src/OpenClaw.Tray.WinUI/Pages/ChatPage.xaml`) and the
233+
tray ChatWindow popup (`src/OpenClaw.Tray.WinUI/Windows/ChatWindow.xaml`)
234+
render their conversations with native WinUI 3 controls via the in-repo
235+
`OpenClawTray.FunctionalUI` helper and `OpenClaw.Chat` model/reducer code.
236+
The standard WebView2-hosted gateway web client remains available as a
237+
settings-controlled fallback.
238+
239+
**Layering:**
240+
241+
```
242+
src/OpenClaw.Tray.WinUI/Chat/ OpenClawChatTimeline · OpenClawComposer · OpenClawSessionHeader
243+
OpenClawChatDataProvider (adapts OpenClawGatewayClient → IChatDataProvider)
244+
OpenClawChatRoot (FunctionalUI component composing the chat surface)
245+
FunctionalChatHostExtensions (mounts FunctionalUI into a XAML <Border>)
246+
IChatGatewayBridge (testability seam over OpenClawGatewayClient)
247+
▲ depends on
248+
src/OpenClaw.Chat/ ChatThread · ChatTimelineState · IChatDataProvider · ChatTimelineReducer
249+
▲ rendered by
250+
src/OpenClawTray.FunctionalUI/ Component · RenderContext · FunctionalHostControl · WinUI elements
251+
```
252+
253+
**Lifecycle:**
254+
255+
- One `OpenClawChatDataProvider` instance lives on `App` (`App.ChatProvider`),
256+
created in `InitializeGatewayClient` and disposed inside
257+
`UnsubscribeGatewayEvents`. Both the Hub Chat tab and the tray ChatWindow
258+
consume the same provider — opening either surface shows identical state.
259+
- Each XAML host (`ChatPage`, `ChatWindow`) mounts its own `FunctionalHostControl`
260+
with `ContentTarget` pointing at a `<Border x:Name="ChatHost"/>`. The
261+
surrounding chrome (NavigationView, popup header) stays XAML.
262+
- Provider events fire on the WebSocket-receive thread; the provider
263+
marshals `Changed` / `NotificationRequested` callbacks through a
264+
dispatcher post delegate (`DispatcherQueue.AsPost()`), so FunctionalUI
265+
components observe state on the UI thread.
266+
267+
**Adding new chat behavior:** model new events in `OpenClaw.Chat`'s
268+
`ChatEvent` discriminated union, handle them in `ChatTimelineReducer`, and
269+
emit them from `OpenClawChatDataProvider` in response to gateway signals.
270+
223271
### Gateway WebSocket Connection
224272

225273
The `OpenClawGatewayClient` manages the connection to the OpenClaw gateway:

‎build.ps1‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ function Build-Project($name, $path, $useRid = $false) {
185185
}
186186
}
187187

188+
function Get-ProjectTargetFramework($path) {
189+
if (-not (Test-Path $path)) {
190+
return $null
191+
}
192+
193+
[xml]$projectXml = Get-Content $path -Raw
194+
return $projectXml.Project.PropertyGroup |
195+
ForEach-Object { $_.TargetFramework } |
196+
Where-Object { $_ } |
197+
Select-Object -First 1
198+
}
199+
188200
$projects = @{
189201
"Shared" = @{ Path = "src/OpenClaw.Shared/OpenClaw.Shared.csproj"; UseRid = $false }
190202
"Cli" = @{ Path = "src/OpenClaw.Cli/OpenClaw.Cli.csproj"; UseRid = $false }
@@ -230,8 +242,16 @@ if ($failCount -eq 0) {
230242
Write-Host "🦞 All builds succeeded!" -ForegroundColor Green
231243

232244
Write-Host "`nTo run:" -ForegroundColor Cyan
233-
if ($buildResults.ContainsKey("WinUI") -or $buildResults.ContainsKey("All")) {
234-
Write-Host " WinUI: .\src\OpenClaw.Tray.WinUI\bin\$Configuration\net10.0-windows10.0.19041.0\$rid\OpenClaw.Tray.WinUI.exe" -ForegroundColor White
245+
if (($buildResults.ContainsKey("WinUI") -and $buildResults["WinUI"]) -or ($buildResults.ContainsKey("Tray") -and $buildResults["Tray"])) {
246+
$winUIProjectPath = $projects["WinUI"].Path
247+
$winUITargetFramework = Get-ProjectTargetFramework $winUIProjectPath
248+
$winUIProjectDirectory = (Split-Path -Parent $winUIProjectPath).Replace("/", "\")
249+
250+
if ($winUITargetFramework) {
251+
Write-Host " WinUI: .\$winUIProjectDirectory\bin\$Configuration\$winUITargetFramework\$rid\OpenClaw.Tray.WinUI.exe" -ForegroundColor White
252+
} else {
253+
Write-Warning "Unable to determine WinUI target framework from $winUIProjectPath"
254+
}
235255
}
236256
} else {
237257
Write-Host "❌ $failCount build(s) failed" -ForegroundColor Red

‎openclaw-windows-node.slnx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<Platform Solution="*|ARM64" Project="ARM64" />
1616
</Project>
1717
<Project Path="src/OpenClaw.Shared/OpenClaw.Shared.csproj" />
18+
<Project Path="src/OpenClaw.Chat/OpenClaw.Chat.csproj">
19+
<Platform Solution="*|Any CPU" Project="x64" />
20+
<Platform Solution="*|x64" Project="x64" />
21+
<Platform Solution="*|ARM64" Project="ARM64" />
22+
</Project>
1823
<Project Path="src/OpenClawTray.FunctionalUI/OpenClawTray.FunctionalUI.csproj" />
1924
<Project Path="src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj">
2025
<!-- WindowsAppSDK.SelfContained requires a concrete Platform (x64/ARM64); AnyCPU would need a RID. -->

‎src/OpenClaw.Chat/ChatModels.cs‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
namespace OpenClaw.Chat;
2+
3+
public enum ChatThreadStatus
4+
{
5+
Created,
6+
Running,
7+
Suspended
8+
}
9+
10+
public enum ChatActivity
11+
{
12+
Idle,
13+
Working,
14+
AwaitingInput,
15+
AwaitingPermission,
16+
Error
17+
}
18+
19+
public enum ChatTimelineItemKind
20+
{
21+
User,
22+
Assistant,
23+
ToolCall,
24+
Reasoning,
25+
Status,
26+
Raw
27+
}
28+
29+
public enum ChatToolCallStatus
30+
{
31+
InProgress,
32+
Success,
33+
Error
34+
}
35+
36+
public enum ChatTone
37+
{
38+
Info,
39+
Success,
40+
Warning,
41+
Error,
42+
Dim
43+
}
44+
45+
public record ChatThread
46+
{
47+
public required string Id { get; init; }
48+
public required string Title { get; init; }
49+
public ChatThreadStatus Status { get; init; }
50+
public ChatActivity Activity { get; init; }
51+
public string? Cwd { get; init; }
52+
public string? Workspace { get; init; }
53+
public string? Repository { get; init; }
54+
public string? Branch { get; init; }
55+
public string? HostName { get; init; }
56+
public string? Compute { get; init; }
57+
public string? ProfileName { get; init; }
58+
public string? Model { get; init; }
59+
public int? HistoryCursor { get; init; }
60+
public DateTimeOffset? CreatedAt { get; init; }
61+
public DateTimeOffset? UpdatedAt { get; init; }
62+
63+
public string DisplayTitle => Title;
64+
}
65+
66+
public record ChatTimelineItem(
67+
string Id,
68+
ChatTimelineItemKind Kind,
69+
string Text,
70+
bool IsStreaming = false,
71+
string? ToolName = null,
72+
ChatToolCallStatus? ToolResult = null,
73+
string? ToolOutput = null,
74+
string? IntentSummary = null,
75+
JsonObject? ToolArgs = null,
76+
ChatTone? Tone = null);
77+
78+
public record ChatPermissionRequest(string RequestId, string PermissionKind, string ToolName, string Detail);
79+
80+
public record ChatTimelineState(
81+
System.Collections.Immutable.ImmutableList<ChatTimelineItem> Entries,
82+
bool TurnActive,
83+
int NextId,
84+
string? ActiveAssistantId,
85+
string? ActiveReasoningId,
86+
string? ActiveToolCallId,
87+
string? CurrentIntent,
88+
System.Collections.Immutable.ImmutableHashSet<string> LocalNonces,
89+
bool HistoryLoaded = false,
90+
ChatPermissionRequest? PendingPermission = null)
91+
{
92+
public static ChatTimelineState Initial() => new(
93+
System.Collections.Immutable.ImmutableList<ChatTimelineItem>.Empty,
94+
false, 1, null, null, null, null,
95+
System.Collections.Immutable.ImmutableHashSet<string>.Empty);
96+
}
97+
98+
public record ChatHistoryPage(ChatEvent[] Events, int NextSince, int PrevBefore, bool HasMore);
99+
100+
public abstract record ChatEvent;
101+
public record ChatUserMessageEvent(string Text, string? Nonce = null) : ChatEvent;
102+
public record ChatThinkingEvent(string Text) : ChatEvent;
103+
public record ChatReasoningEvent(string Text) : ChatEvent;
104+
public record ChatReasoningDeltaEvent(string Text) : ChatEvent;
105+
public record ChatMessageEvent(string Text, string? ReasoningText = null, bool ReconcilePrevious = false) : ChatEvent;
106+
public record ChatMessageDeltaEvent(string Text) : ChatEvent;
107+
public record ChatTurnEndEvent() : ChatEvent;
108+
public record ChatIntentEvent(string Intent) : ChatEvent;
109+
public record ChatToolStartEvent(string Text, string ToolName, JsonObject? ToolArgs = null) : ChatEvent;
110+
public record ChatToolOutputEvent(string Text) : ChatEvent;
111+
public record ChatToolErrorEvent(string Text) : ChatEvent;
112+
public record ChatContextChangedEvent(string? Cwd, string? GitBranch) : ChatEvent;
113+
public record ChatStatusEvent(string Text, ChatTone Tone) : ChatEvent;
114+
public record ChatErrorEvent(string Text) : ChatEvent;
115+
public record ChatRestoredEvent(string Text) : ChatEvent;
116+
public record ChatPermissionRequestEvent(string RequestId, string PermissionKind, string ToolName, string Detail) : ChatEvent;
117+
public record ChatModelChangedEvent(string Model) : ChatEvent;
118+
public record ChatRawEvent(string EventType, string? Text = null) : ChatEvent;
119+
120+
public record ChatDataSnapshot(
121+
ChatThread[] Threads,
122+
IReadOnlyDictionary<string, ChatTimelineState> Timelines,
123+
string? DefaultThreadId,
124+
string? ConnectionStatus,
125+
string[] AvailableModels);
126+
127+
public sealed class ChatDataChangedEventArgs(ChatDataSnapshot snapshot) : EventArgs
128+
{
129+
public ChatDataSnapshot Snapshot { get; } = snapshot;
130+
}
131+
132+
public enum ChatProviderNotificationKind
133+
{
134+
TurnComplete,
135+
PermissionRequested,
136+
Error
137+
}
138+
139+
public record ChatProviderNotification(
140+
ChatProviderNotificationKind Kind,
141+
string ThreadId,
142+
string Title,
143+
string? Message = null,
144+
string? ToolName = null);
145+
146+
public sealed class ChatProviderNotificationEventArgs(ChatProviderNotification notification) : EventArgs
147+
{
148+
public ChatProviderNotification Notification { get; } = notification;
149+
}
150+
151+
public interface IChatDataProvider : IAsyncDisposable
152+
{
153+
string DisplayName { get; }
154+
155+
event EventHandler<ChatDataChangedEventArgs>? Changed;
156+
event EventHandler<ChatProviderNotificationEventArgs>? NotificationRequested;
157+
158+
Task<ChatDataSnapshot> LoadAsync(CancellationToken cancellationToken = default);
159+
Task<ChatThread> CreateThreadAsync(string? initialMessage = null, CancellationToken cancellationToken = default);
160+
Task SendMessageAsync(string threadId, string message, CancellationToken cancellationToken = default);
161+
Task StopResponseAsync(string threadId, CancellationToken cancellationToken = default);
162+
Task SetThreadSuspendedAsync(string threadId, bool suspended, CancellationToken cancellationToken = default);
163+
Task DeleteThreadAsync(string threadId, CancellationToken cancellationToken = default);
164+
Task SetModelAsync(string threadId, string model, CancellationToken cancellationToken = default);
165+
Task SetPermissionModeAsync(string threadId, bool allowAll, CancellationToken cancellationToken = default);
166+
Task RespondToPermissionAsync(string threadId, string requestId, bool allow, CancellationToken cancellationToken = default);
167+
}

0 commit comments

Comments
 (0)