1+ import BuiltinExtension
12import ChatGPTChatTab
23import ChatService
34import ChatTab
@@ -9,20 +10,11 @@ import XcodeInspector
910
1011#if canImport(ProChatTabs)
1112import ProChatTabs
13+ #endif
1214
1315enum ChatTabFactory {
1416 static func chatTabBuilderCollection( ) -> [ ChatTabBuilderCollection ] {
15- func folderIfNeeded(
16- _ builders: [ any ChatTabBuilder ] ,
17- title: String
18- ) -> ChatTabBuilderCollection ? {
19- if builders. count > 1 {
20- return . folder( title: title, kinds: builders. map ( ChatTabKind . init) )
21- }
22- if let first = builders. first { return . kind( ChatTabKind ( first) ) }
23- return nil
24- }
25-
17+ #if canImport(ProChatTabs)
2618 let collection = [
2719 folderIfNeeded ( ChatGPTChatTab . chatBuilders ( ) , title: ChatGPTChatTab . name) ,
2820 folderIfNeeded (
@@ -32,11 +24,34 @@ enum ChatTabFactory {
3224 title: BrowserChatTab . name
3325 ) ,
3426 folderIfNeeded ( TerminalChatTab . chatBuilders ( ) , title: TerminalChatTab . name) ,
35- ] . compactMap { $0 }
27+ ]
28+ #else
29+ let collection = [
30+ folderIfNeeded ( ChatGPTChatTab . chatBuilders ( ) , title: ChatGPTChatTab . name) ,
31+ ]
32+ #endif
3633
37- return collection
34+ return collection. compactMap { $0 } + chatTabsFromExtensions ( )
3835 }
3936
37+ private static func folderIfNeeded(
38+ _ builders: [ any ChatTabBuilder ] ,
39+ title: String
40+ ) -> ChatTabBuilderCollection ? {
41+ if builders. count > 1 {
42+ return . folder( title: title, kinds: builders. map ( ChatTabKind . init) )
43+ }
44+ if let first = builders. first { return . kind( ChatTabKind ( first) ) }
45+ return nil
46+ }
47+
48+ static func chatTabsFromExtensions( ) -> [ ChatTabBuilderCollection ] {
49+ let extensions = BuiltinExtensionManager . shared. extensions
50+ let chatBuilders = extensions. flatMap { $0. chatBuilders }
51+ return chatBuilders. compactMap { folderIfNeeded ( $0. value, title: $0. key) }
52+ }
53+
54+ #if canImport(ProChatTabs)
4055 static func externalDependenciesForBrowserChatTab( ) -> BrowserChatTab . ExternalDependency {
4156 . init(
4257 getEditorContent: {
@@ -109,28 +124,6 @@ enum ChatTabFactory {
109124 }
110125 )
111126 }
127+ #endif
112128}
113129
114- #else
115-
116- enum ChatTabFactory {
117- static func chatTabBuilderCollection( ) -> [ ChatTabBuilderCollection ] {
118- func folderIfNeeded(
119- _ builders: [ any ChatTabBuilder ] ,
120- title: String
121- ) -> ChatTabBuilderCollection ? {
122- if builders. count > 1 {
123- return . folder( title: title, kinds: builders. map ( ChatTabKind . init) )
124- }
125- if let first = builders. first { return . kind( ChatTabKind ( first) ) }
126- return nil
127- }
128-
129- return [
130- folderIfNeeded ( ChatGPTChatTab . chatBuilders ( ) , title: ChatGPTChatTab . name) ,
131- ] . compactMap { $0 }
132- }
133- }
134-
135- #endif
136-
0 commit comments