CI / ci (push) Canceled after 0s
Profiles S2 over the variant C verdict (#130): Settings becomes a sidebar + detail shell — Content (the #17 Home control, unchanged) · Pass 1 · Pass 2 · Chat ('· Sessions' rides it) · Provider Keys. Each surface page edits its model block in memory: provider menu, an NSComboBox sourcing hermes' registry cache with first-class free text (the #132 seed claude-sonnet-5-5 is NOT in the cache — custom is the default state, pinned), per-provider effort menus led by 'unset · provider default' (zai low/high/max; OpenAI + Anthropic the five-rung ladder), variant B's current-model headline, and a user-requested Restore Defaults back to the seed. Provider Keys carries endpoint, the z.ai key-type toggle swapping the endpoint family (paas/v4 ↔ coding/paas/v4 — a custom endpoint survives), and masked keys with reveal; no Keychain (#131). Persistence is S3's job: every change routes through an injectable SettingsWriting seam whose implementer contract is frozen now (MUST debounce — the key field fires per keystroke; secrets via stdin/env, never argv; error text redacted before it renders). Write failures surface in an orange strip, cleared by the next success. Dogfood fix, log-observed via os_log probes on the live app: comboBoxSelectionDidChange fires BEFORE stringValue updates — the pick is read from objectValueOfSelectedItem and the box re-synced by hand, or the model never learns a dropdown pick. Two blind fixes failed before the probe round settled it; pinned against the stale-string fixture and filed to the swift wiki. Finish-audit fanout (ponytail/security/general): Ship/SHIP/APPROVE — applied the SettingsWriting contract, an inlined one-caller wrapper, a corrected registry-leniency comment, and a seed-provider pin; declined deleting the hydration clamp (trust-boundary validation for S3's config.yaml reads); deferred endpoint scheme validation to S3's write boundary. Suite: 432 passed / 432 (xcresult-verified). DOX: Museion/AGENTS.md, MuseionTests/AGENTS.md, CHANGELOG, session log. Closes #135
274 lines
8.5 KiB
Swift
274 lines
8.5 KiB
Swift
//
|
|
// SettingsPagesView.swift
|
|
// Museion
|
|
//
|
|
// #135 (Profiles S2): the Settings sidebar's detail pages over the
|
|
// in-memory SettingsModel — one page per LLM surface (provider select,
|
|
// registry combobox with first-class free text, per-provider effort menu)
|
|
// and the Provider Keys page (endpoint, z.ai key-type toggle swapping the
|
|
// endpoint family, masked key + reveal). Visual contract: #130 prototype
|
|
// variant C, with variant B's current-model headline folded in.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// The quiet field label (prototype `.field-label`, #130 fold-in): mono
|
|
/// 10.5 uppercase, one line, never a wrapping caption.
|
|
struct SettingsFieldLabel: View {
|
|
let text: String
|
|
|
|
init(_ text: String) {
|
|
self.text = text
|
|
}
|
|
|
|
var body: some View {
|
|
Text(text)
|
|
.font(.system(size: 10.5, design: DesignTokens.mono))
|
|
.lineLimit(1)
|
|
.tracking(0.5)
|
|
.textCase(.uppercase)
|
|
.foregroundStyle(DesignTokens.muted)
|
|
}
|
|
}
|
|
|
|
/// One surface's model page (prototype `.vC .detail` surface branch +
|
|
/// variant B's `.current` headline): provider, model combobox, reasoning
|
|
/// effort. Output budget is not a control (#128).
|
|
struct SurfaceSettingsPage: View {
|
|
let model: SettingsModel
|
|
let surface: ProfileSurface
|
|
|
|
var body: some View {
|
|
let config = model.config(for: surface)
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
HStack {
|
|
Text(label)
|
|
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
|
|
Spacer(minLength: 12)
|
|
// macOS convention: Restore Defaults in the page header.
|
|
Button("Restore Defaults") {
|
|
model.resetToDefault(for: surface)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.controlSize(.small)
|
|
.disabled(config == .surfaceDefault)
|
|
}
|
|
// Variant B's stolen headline: the current model reads first.
|
|
Text(config.model + (model.isCustom(surface) ? " · custom (not in registry)" : ""))
|
|
.font(.system(size: 12.5, design: DesignTokens.mono))
|
|
.foregroundStyle(DesignTokens.accent)
|
|
Text("profile · \(surface.profileName) — \(note)")
|
|
.font(.system(size: 11, design: DesignTokens.mono))
|
|
.foregroundStyle(DesignTokens.muted)
|
|
VStack(alignment: .leading, spacing: 14) {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
SettingsFieldLabel("Provider")
|
|
Picker("Provider", selection: Binding(
|
|
get: { config.provider },
|
|
set: { model.setProvider($0, for: surface) },
|
|
)) {
|
|
ForEach(ModelProvider.allCases, id: \.self) { provider in
|
|
Text(provider.label).tag(provider)
|
|
}
|
|
}
|
|
.pickerStyle(.menu)
|
|
.frame(width: 200)
|
|
}
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
SettingsFieldLabel("Model")
|
|
HStack(spacing: 8) {
|
|
ModelComboBox(
|
|
value: config.model,
|
|
items: model.registry.list(for: config.provider),
|
|
) { model.setModel($0, for: surface) }
|
|
.frame(width: 240)
|
|
if model.isCustom(surface) {
|
|
Text("custom (not in registry)")
|
|
.font(.system(size: 11, design: DesignTokens.mono))
|
|
.foregroundStyle(DesignTokens.muted)
|
|
}
|
|
}
|
|
}
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
SettingsFieldLabel("Reasoning Effort")
|
|
Picker("Reasoning Effort", selection: Binding(
|
|
get: { config.effort },
|
|
set: { model.setEffort($0, for: surface) },
|
|
)) {
|
|
Text("unset · provider default").tag(ReasoningEffort?.none)
|
|
// The provider's ladder only — a provider switch
|
|
// rebuilds this menu (and resets the choice).
|
|
ForEach(config.provider.effortOptions, id: \.self) { effort in
|
|
Text(effort.rawValue).tag(ReasoningEffort?.some(effort))
|
|
}
|
|
}
|
|
.pickerStyle(.menu)
|
|
.frame(width: 200)
|
|
}
|
|
Text("Output budget fixed at \(ProfileSurface.outputBudgetTokens / 1000)k tokens — not a setting.")
|
|
.font(.system(size: 11.5))
|
|
.foregroundStyle(DesignTokens.muted)
|
|
}
|
|
.padding(.top, 12)
|
|
}
|
|
.frame(maxWidth: DesignTokens.settingsFormWidth, alignment: .leading)
|
|
.padding(.horizontal, 26)
|
|
.padding(.top, 18)
|
|
.padding(.bottom, 48)
|
|
}
|
|
|
|
private var label: String {
|
|
switch surface {
|
|
case .pass1: "Pass 1"
|
|
case .pass2: "Pass 2"
|
|
case .chat: "Chat"
|
|
}
|
|
}
|
|
|
|
/// The page's posture note (prototype `SURFACES[].note`): passes apply
|
|
/// on the next run (on-demand engines, ADR-0014); Chat is the resident
|
|
/// engine Sessions rides, restarted in place on a model change (#129).
|
|
private var note: String {
|
|
switch surface {
|
|
case .pass1, .pass2: "applies on the next pass"
|
|
case .chat: "Sessions rides this engine · a model change restarts it (after any streaming turn)"
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The Provider Keys page (#135): one block per provider — endpoint, z.ai
|
|
/// key-type toggle, masked API key + reveal. One key per provider fans out
|
|
/// to every profile on that provider; no Keychain (#131 verdict).
|
|
struct ProviderKeysPage: View {
|
|
let model: SettingsModel
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text("Provider Keys")
|
|
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
|
|
Text("One key per provider, fanned out to every profile on it. No Keychain.")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(DesignTokens.muted)
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
ForEach(ModelProvider.allCases, id: \.self) { provider in
|
|
ProviderKeyBlock(model: model, provider: provider)
|
|
}
|
|
}
|
|
.padding(.top, 12)
|
|
}
|
|
.frame(maxWidth: DesignTokens.settingsFormWidth + 60, alignment: .leading)
|
|
.padding(.horizontal, 26)
|
|
.padding(.top, 18)
|
|
.padding(.bottom, 48)
|
|
}
|
|
}
|
|
|
|
/// One provider's key block (prototype `.block`).
|
|
private struct ProviderKeyBlock: View {
|
|
let model: SettingsModel
|
|
let provider: ModelProvider
|
|
@State private var revealed = false
|
|
|
|
var body: some View {
|
|
let config = model.keyConfig(for: provider)
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
HStack {
|
|
Text(provider.label)
|
|
.font(.system(size: 14, weight: .semibold, design: DesignTokens.serif))
|
|
Spacer(minLength: 12)
|
|
if provider == .zai {
|
|
KeyTypeSegment(model: model)
|
|
}
|
|
}
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
SettingsFieldLabel("Endpoint (Base URL)")
|
|
TextField(
|
|
"Endpoint",
|
|
text: Binding(
|
|
get: { config.endpoint },
|
|
set: { model.setEndpoint($0, for: provider) },
|
|
),
|
|
)
|
|
.font(.system(size: 11.5, design: DesignTokens.mono))
|
|
}
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
SettingsFieldLabel("API Key")
|
|
HStack(spacing: 6) {
|
|
if revealed {
|
|
TextField("API key", text: Binding(
|
|
get: { config.apiKey },
|
|
set: { model.setAPIKey($0, for: provider) },
|
|
))
|
|
.font(.system(size: 11.5, design: DesignTokens.mono))
|
|
} else {
|
|
SecureField("API key", text: Binding(
|
|
get: { config.apiKey },
|
|
set: { model.setAPIKey($0, for: provider) },
|
|
))
|
|
.font(.system(size: 11.5, design: DesignTokens.mono))
|
|
}
|
|
Button(revealed ? "hide" : "show") {
|
|
revealed.toggle()
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.controlSize(.small)
|
|
.font(.system(size: 11, design: DesignTokens.mono))
|
|
}
|
|
}
|
|
if provider == .zai {
|
|
Text("Key type picks the endpoint family — coding-plan keys are distribution-restricted; shipped Museion uses standard keys.")
|
|
.font(.system(size: 11.5))
|
|
.foregroundStyle(DesignTokens.muted)
|
|
}
|
|
}
|
|
.padding(EdgeInsets(top: 14, leading: 16, bottom: 14, trailing: 16))
|
|
.background(
|
|
RoundedRectangle(cornerRadius: DesignTokens.radius)
|
|
.fill(DesignTokens.surface)
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: DesignTokens.radius)
|
|
.strokeBorder(DesignTokens.border),
|
|
),
|
|
)
|
|
}
|
|
}
|
|
|
|
/// The z.ai key-type toggle (prototype `.seg`): a two-segment capsule, the
|
|
/// selected segment filled with the foreground ink. Toggling swaps the
|
|
/// endpoint family (the model guards a custom endpoint).
|
|
private struct KeyTypeSegment: View {
|
|
let model: SettingsModel
|
|
|
|
var body: some View {
|
|
HStack(spacing: 0) {
|
|
ForEach(ZaiKeyType.allCases, id: \.self) { type in
|
|
let selected = model.zaiKeyType == type
|
|
Button {
|
|
model.setZaiKeyType(type)
|
|
} label: {
|
|
Text(type.label)
|
|
.font(.system(size: 11.5))
|
|
.padding(.horizontal, 10)
|
|
.padding(.vertical, 4)
|
|
.foregroundStyle(selected ? DesignTokens.background : DesignTokens.muted)
|
|
.background {
|
|
if selected {
|
|
RoundedRectangle(cornerRadius: 6)
|
|
.fill(DesignTokens.foreground)
|
|
.padding(1)
|
|
}
|
|
}
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityAddTraits(selected ? [.isSelected] : [])
|
|
}
|
|
}
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 7)
|
|
.fill(DesignTokens.surface)
|
|
.overlay(RoundedRectangle(cornerRadius: 7).strokeBorder(DesignTokens.border)),
|
|
)
|
|
.accessibilityLabel("z.ai key type")
|
|
}
|
|
}
|