import SwiftUI import TermindDomain /// The same endpoint derivation is presented in desktop pages and mobile drafts. public struct ModelProviderConnectionFields: View { @Binding private var isEnabled: Bool @Binding private var name: String @Binding private var endpoint: ProviderEndpoint private let showsEndpoint: Bool public init( name: Binding, endpoint: Binding, isEnabled: Binding, showsEndpoint: Bool = true ) { _isEnabled = isEnabled _name = name _endpoint = endpoint self.showsEndpoint = showsEndpoint } private var preview: ProviderEndpoint { endpoint.withDefaultURL } public var body: some View { Section { LabeledContent("Name") { TextField( "Name", text: $name.singleLineText, prompt: Text(verbatim: endpoint.apiType.defaultProviderName), axis: .horizontal ) .singleLinePaste().lineLimit(1).labelsHidden().multilineTextAlignment(.trailing) } Toggle("Enabled", isOn: $isEnabled) Picker("API Type", selection: $endpoint.apiType) { ForEach(ModelAPIType.allCases) { Text($0.displayName).tag($0) } } } if showsEndpoint { Section("Endpoint") { LabeledContent("URL") { TextField( "URL", text: $endpoint.url.singleLineText, prompt: Text(verbatim: endpoint.apiType.defaultURL), axis: .horizontal ).singleLinePaste().lineLimit(1) .labelsHidden() .autocorrectionDisabled() .multilineTextAlignment(.trailing) } if !ModelProviderForm.isValidURL(preview.requestURL) { Text("Enter a valid provider URL, or a Vertex project and location.") .font(.caption).foregroundStyle(.red) } if preview.isConfigured { LabeledContent("Full URL") { Text(preview.requestURL).font(.caption.monospaced()).textSelection(.enabled) .multilineTextAlignment(.trailing).fixedSize(horizontal: false, vertical: true) } Text("Requests use the \(preview.format.displayName) format.") .font(.caption).foregroundStyle(.secondary) } } } } }