@@ -7,6 +7,10 @@ import Environment
77import Preferences
88import SuggestionWidget
99
10+ #if canImport(ChatTabPersistent)
11+ import ChatTabPersistent
12+ #endif
13+
1014struct GUI : ReducerProtocol {
1115 struct State : Equatable {
1216 var suggestionWidgetState = WidgetFeature . State ( )
@@ -15,6 +19,17 @@ struct GUI: ReducerProtocol {
1519 get { suggestionWidgetState. chatPanelState. chatTapGroup }
1620 set { suggestionWidgetState. chatPanelState. chatTapGroup = newValue }
1721 }
22+
23+ #if canImport(ChatTabPersistent)
24+ var persistentState : ChatTabPersistent . State {
25+ get {
26+ . init( chatTabInfo: suggestionWidgetState. chatPanelState. chatTapGroup. tabInfo)
27+ }
28+ set {
29+ suggestionWidgetState. chatPanelState. chatTapGroup. tabInfo = newValue. chatTabInfo
30+ }
31+ }
32+ #endif
1833 }
1934
2035 enum Action {
@@ -23,6 +38,10 @@ struct GUI: ReducerProtocol {
2338 case sendCustomCommandToActiveChat( CustomCommand )
2439
2540 case suggestionWidget( WidgetFeature . Action )
41+
42+ #if canImport(ChatTabPersistent)
43+ case persistent( ChatTabPersistent . Action )
44+ #endif
2645 }
2746
2847 @Dependency ( \. chatTabPool) var chatTabPool : ChatTabPool
@@ -65,6 +84,12 @@ struct GUI: ReducerProtocol {
6584 }
6685 }
6786
87+ #if canImport(ChatTabPersistent)
88+ Scope ( state: \. persistentState, action: / Action. persistent) {
89+ ChatTabPersistent ( )
90+ }
91+ #endif
92+
6893 Reduce { state, action in
6994 switch action {
7095 case let . openChatPanel( forceDetach) :
@@ -126,8 +151,22 @@ struct GUI: ReducerProtocol {
126151 }
127152 }
128153
154+ case . suggestionWidget( . chatPanel( . chatTab( _, . tabContentUpdated) ) ) :
155+ #if canImport(ChatTabPersistent)
156+ return . run { send in
157+ await send ( . persistent( . persistChatTabs) )
158+ }
159+ #else
160+ return . none
161+ #endif
162+
129163 case . suggestionWidget:
130164 return . none
165+
166+ #if canImport(ChatTabPersistent)
167+ case . persistent:
168+ return . none
169+ #endif
131170 }
132171 }
133172 }
@@ -213,28 +252,27 @@ extension ChatTabPool {
213252 @MainActor
214253 func createTab(
215254 from builder: ChatTabBuilder
216- ) -> ( any ChatTab , ChatTabInfo ) ? {
255+ ) async -> ( any ChatTab , ChatTabInfo ) ? {
217256 let id = UUID ( ) . uuidString
218257 let info = ChatTabInfo ( id: id, title: " " )
219- guard builder. buildable else { return nil }
220- let chatTap = builder. build ( store: createStore ( id) )
258+ guard let chatTap = await builder. build ( store: createStore ( id) ) else { return nil }
221259 setTab ( chatTap)
222260 return ( chatTap, info)
223261 }
224262
225263 @MainActor
226264 func createTab(
227265 for kind: ChatTabKind ?
228- ) -> ( any ChatTab , ChatTabInfo ) ? {
266+ ) async -> ( any ChatTab , ChatTabInfo ) ? {
229267 let id = UUID ( ) . uuidString
230268 let info = ChatTabInfo ( id: id, title: " " )
231269 guard let builder = kind? . builder else {
232270 let chatTap = ChatGPTChatTab ( store: createStore ( id) )
233271 setTab ( chatTap)
234272 return ( chatTap, info)
235273 }
236- guard builder . buildable else { return nil }
237- let chatTap = builder. build ( store: createStore ( id) )
274+
275+ guard let chatTap = await builder. build ( store: createStore ( id) ) else { return nil }
238276 setTab ( chatTap)
239277 return ( chatTap, info)
240278 }
0 commit comments