Skip to content
Merged
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
50 changes: 49 additions & 1 deletion ios/TaskWraithKit/Sources/TaskWraithUI/NewChatCanvas.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct NewChatBootstrapView: View {

@State private var createdThreadId: String?
@State private var requestedKey: String?
@State private var createFailed = false

private var targetWorkspaceId: String? {
switch mode {
Expand All @@ -37,6 +38,8 @@ struct NewChatBootstrapView: View {
Group {
if let threadId = createdThreadId {
detailHost(threadId: threadId)
} else if createFailed {
failureView
} else {
VStack(spacing: 12) {
TaskWraithMonolineBrandView(markSize: 44, titleSize: 20)
Expand Down Expand Up @@ -86,17 +89,62 @@ struct NewChatBootstrapView: View {
}
}

private var failureView: some View {
VStack(spacing: 14) {
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 32))
.foregroundStyle(TWTheme.textMuted)
Text(failureTitle)
.font(.headline)
.foregroundStyle(TWTheme.textPrimary)
.multilineTextAlignment(.center)
Text(model.lastActionMessage ?? "Your Mac declined the request.")
.font(.callout)
.foregroundStyle(TWTheme.textSecondary)
.multilineTextAlignment(.center)
.fixedSize(horizontal: false, vertical: true)
Button {
createFailed = false
createIfReady()
} label: {
Text("Try Again").font(.callout.weight(.semibold))
}
.buttonStyle(.borderedProminent)
.tint(TWTheme.chroma1)
.padding(.top, 2)
}
.padding(28)
.frame(maxWidth: 420)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(TWTheme.appBg)
}

private var failureTitle: String {
switch mode {
case .workspace: return "Couldn't start this chat"
case .ensemble: return "Couldn't start this ensemble"
case .global: return "Couldn't start a global chat"
}
}

private func createIfReady() {
guard createdThreadId == nil, let workspaceId = targetWorkspaceId else { return }
let key = "\(variant):\(workspaceId)"
guard requestedKey != key else { return }
requestedKey = key
createFailed = false
model.createEmptyThread(
workspaceId: workspaceId,
variant: variant,
title: "New Chat"
) { threadId in
guard let threadId else { return }
guard let threadId else {
// Mac declined (or the request failed) — stop spinning, surface
// the reason, and allow Retry (clear the latched key).
requestedKey = nil
createFailed = true
return
}
createdThreadId = threadId
}
}
Expand Down
28 changes: 19 additions & 9 deletions ios/TaskWraithKit/Sources/TaskWraithUI/RemoteSessionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2441,16 +2441,26 @@ public final class RemoteSessionModel: ObservableObject {
title: title),
timeoutMs: 12_000,
successLabel: "Chat created.",
navigateOnAck: true
) { [weak self] threadId in
guard let self, let threadId else {
onCreated?(nil)
return
navigateOnAck: true,
onThreadCreated: { [weak self] threadId in
guard let self, let threadId else {
onCreated?(nil)
return
}
self.rememberThreadWorkspace(threadId, workspaceId: workspaceId)
self.scheduleThreadRefresh(threadId)
onCreated?(threadId)
},
// A denied/failed create never reaches onThreadCreated (send only
// fires that when accepted), which left the new-chat canvas spinning
// on "Creating…" forever — exactly what "can't start a global /
// ensemble chat" looks like. Surface the failure so the canvas can
// show the Mac's reason (e.g. ensemble mode disabled, global not
// shared while the workspace allowlist is empty) and offer Retry.
onAck: { accepted in
if !accepted { onCreated?(nil) }
}
self.rememberThreadWorkspace(threadId, workspaceId: workspaceId)
self.scheduleThreadRefresh(threadId)
onCreated?(threadId)
}
)
}

/// Create an empty ensemble chat, optionally queue the first prompt.
Expand Down
Loading