import SwiftUI import LChatCore // 🤖 Mac host for Eleven's native onboarding conversation (setup / welcome): // the takeover pane NativeChatView routes these app-threads to. The finish // chips' thread hop selects the target in the sidebar. struct ElevenConversationPane: View { let instance: SavedInstance let thread: ChatThread @ObservedObject var store: ThreadStore @Binding var selectedID: String? @EnvironmentObject private var app: MacAppState @State private var model: ElevenConversationModel? @State private var showDiscover = false @State private var showQuickForm = false @AppStorage(ChatTextSize.key) private var chatTextSize = ChatTextSize.defaultSize @AppStorage("nativeTheme") private var themeName = "classic" var body: some View { Group { if let model { ElevenChatView(model: model, theme: .named(themeName)) .environment(\.chatFontSize, CGFloat(ChatTextSize.snap(chatTextSize))) } else { ProgressView().frame(maxWidth: .infinity, maxHeight: .infinity) } } .sheet(isPresented: $showDiscover) { // The community directory (shared view; web: showDiscover) — the // welcome finish's "Browse open groups" chip lands here. Mirrors // NativeChatView's Discover sheet. VStack(spacing: 0) { DiscoverGroupsView(store: store) { threadID in showDiscover = false selectedID = threadID } Divider() HStack { Spacer() Button("Done") { showDiscover = false } .keyboardShortcut(.cancelAction) } .padding(12) } .frame(minWidth: 420, minHeight: 420) } .sheet(isPresented: $showQuickForm) { // "Fill in a form instead" — the whole conversation's questions at // once; submitting fast-fills the flow's records and it resumes. if let model { ElevenQuickFormView(model: model) } } .onAppear { guard model == nil else { return } let m = ElevenConversationCache.shared.model(for: instance, thread: thread, myUserId: store.myUserId) m?.openQuickForm = { showQuickForm = true } m?.openThread = { id in selectedID = id } m?.openAdmin = { Task { @MainActor in if let id = await store.openOrCreateAppThread(app: "admin", title: "Admin") { selectedID = id } } } m?.openDiscover = { showDiscover = true } // Outgoing payloads stamp the SavedInstance's name — persist a // flow rename, the way MacSettingsView persists a manual one. m?.onNameSet = { name in app.noteIdentity(origin: instance.origin, token: instance.deviceToken, name: name, userPub: instance.userPub, userPriv: instance.userPriv) } m?.start(roster: store.roster, threads: store.threads) model = m } } }