forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseURLSelection.swift
More file actions
50 lines (42 loc) · 1.51 KB
/
BaseURLSelection.swift
File metadata and controls
50 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import ComposableArchitecture
import Foundation
import Preferences
import SwiftUI
struct BaseURLSelection: ReducerProtocol {
struct State: Equatable {
@BindingState var baseURL: String = ""
var availableBaseURLs: [String] = []
}
enum Action: Equatable, BindableAction {
case appear
case refreshAvailableBaseURLNames
case binding(BindingAction<State>)
}
@Dependency(\.toast) var toast
@Dependency(\.userDefaults) var userDefaults
var body: some ReducerProtocol<State, Action> {
BindingReducer()
Reduce { state, action in
switch action {
case .appear:
return .run { send in
await send(.refreshAvailableBaseURLNames)
}
case .refreshAvailableBaseURLNames:
let chatModels = userDefaults.value(for: \.chatModels)
let embeddingModels = userDefaults.value(for: \.embeddingModels)
var allBaseURLs = Set(
chatModels.map(\.info.baseURL)
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
+ embeddingModels.map(\.info.baseURL)
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
)
allBaseURLs.remove("")
state.availableBaseURLs = Array(allBaseURLs).sorted()
return .none
case .binding:
return .none
}
}
}
}