Skip to content

Commit 32d6c29

Browse files
authored
Merge pull request #57 from mcintyre94/chat-session-state-issue-f108b1db
Fix chat showing thinking shimmer instead of reconnecting state on reopen
2 parents 543d38e + 4ea18ee commit 32d6c29

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

Wisp/ViewModels/ChatViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ enum ChatStatus: Sendable {
1717
if case .connecting = self { return true }
1818
return false
1919
}
20+
21+
var isReconnecting: Bool {
22+
if case .reconnecting = self { return true }
23+
return false
24+
}
2025
}
2126

2227
struct AttachedFile: Identifiable {
@@ -994,7 +999,6 @@ final class ChatViewModel {
994999
serviceName: serviceName
9951000
)
9961001

997-
status = .streaming
9981002
let streamResult = await processServiceStream(
9991003
stream: stream,
10001004
modelContext: modelContext

Wisp/Views/SpriteDetail/Chat/ChatView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct ChatView: View {
3636
ForEach(viewModel.messages) { message in
3737
messageView(message)
3838
}
39-
if viewModel.isStreaming && viewModel.pendingWispAskCard == nil {
39+
if viewModel.isStreaming && !viewModel.status.isReconnecting && viewModel.pendingWispAskCard == nil {
4040
ThinkingShimmerView(label: viewModel.status.isConnecting ? "Connecting…" : (viewModel.activeToolLabel ?? "Thinking…"))
4141
.transition(.opacity.combined(with: .move(edge: .bottom)))
4242
.id("shimmer")

WispTests/ChatViewModelTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,44 @@ struct ChatViewModelTests {
629629
#expect(vm.processedEventUUIDs.isEmpty)
630630
}
631631

632+
// MARK: - ChatStatus computed properties
633+
634+
@Test func chatStatus_isConnecting_onlyForConnecting() {
635+
#expect(ChatStatus.connecting.isConnecting == true)
636+
#expect(ChatStatus.streaming.isConnecting == false)
637+
#expect(ChatStatus.reconnecting.isConnecting == false)
638+
#expect(ChatStatus.idle.isConnecting == false)
639+
#expect(ChatStatus.error("x").isConnecting == false)
640+
}
641+
642+
@Test func chatStatus_isReconnecting_onlyForReconnecting() {
643+
#expect(ChatStatus.reconnecting.isReconnecting == true)
644+
#expect(ChatStatus.connecting.isReconnecting == false)
645+
#expect(ChatStatus.streaming.isReconnecting == false)
646+
#expect(ChatStatus.idle.isReconnecting == false)
647+
#expect(ChatStatus.error("x").isReconnecting == false)
648+
}
649+
650+
@Test func chatStatus_isStreaming_trueForActiveStates() throws {
651+
let ctx = try makeModelContext()
652+
let (vm, _) = makeChatViewModel(modelContext: ctx)
653+
654+
vm.status = .connecting
655+
#expect(vm.isStreaming == true)
656+
657+
vm.status = .streaming
658+
#expect(vm.isStreaming == true)
659+
660+
vm.status = .reconnecting
661+
#expect(vm.isStreaming == true)
662+
663+
vm.status = .idle
664+
#expect(vm.isStreaming == false)
665+
666+
vm.status = .error("oops")
667+
#expect(vm.isStreaming == false)
668+
}
669+
632670
// MARK: - Streaming state (single source of truth)
633671

634672
@Test func currentAssistantMessageId_tracksCurrentMessage() throws {

0 commit comments

Comments
 (0)