CI / ci (push) Canceled after 0s
#181: ModelProvider is the provider-descriptor table — label, effort ladder, flagship, endpoint, env var joined by wire dialect (chat/models paths + the SSE decoder selector), auth mode (Bearer vs Anthropic's header pair), keyless (nous rides the Portal login), and the ONE trailing-slash endpoint trim. The probe's URL builders, auth headers, and stream-decoder picks select by data; the per-dialect bodies and decoders stay separate functions, not switch clothing. ProviderCredential.resolve is the ONE credential rail (provider key, else the shared Portal session key for keyless providers — official endpoint ONLY, never a user-set URL). Settings' Test Connection and the new PassReadiness module both call it; the twice-implemented #175 fallback can no longer drift. One deliberate tightening, reviewer- blessed: a nous pass profile on a custom base_url with no pasted key now reads missingKey where the old session-model fallback said ready — the old copy had no endpoint gate at all. Pass readiness leaves the session model (PassReadiness.swift maps each pass surface to ready/missingKey/unknown over the descriptor; MentorSessionModel stores the verdicts and reads no keys or auth files). runPass and blindRead run their guards through one shared rail (guardOpenPieceRun) — identical refusal strings, blockers named honestly. No app-side model-settings store (ADR-0014 red line). Rider: the #179 mid-pass repoint pin polls the rig's hasHeldPrompt before releasing the held turn — runningPass flips before the one-shot engine parks its prompt, so firing into that window false-failed under parallel-suite load. Full suite 668/668 (xcresult executed count). Finish-audit: three reviewers (ponytail/security/general), zero findings above LOW; two ponytail trims and one pin tightening applied. Closes #181
80 lines
2.9 KiB
Swift
80 lines
2.9 KiB
Swift
//
|
|
// PassReadiness.swift
|
|
// Museion
|
|
//
|
|
|
|
// ## Scenario: pass readiness over the provider descriptor
|
|
// From #181
|
|
//
|
|
// Given the pass profiles' providers read through the settings seam
|
|
// When pass readiness refreshes
|
|
// Then each pass surface maps to ready / missingKey / unknown through the
|
|
// ONE credential resolution (provider key, else the Portal session key
|
|
// for keyless providers) — the session model stores the verdicts and
|
|
// itself reads no keys and no auth files.
|
|
|
|
import Foundation
|
|
|
|
/// #181: per-pass readiness — ready / missingKey / unknown, computed
|
|
/// over the provider descriptor. Formerly the session model's #137
|
|
/// nested enum: the profile reads (surface provider, `.env` key, Portal
|
|
/// auth store) live HERE now; MentorSessionModel stores the verdicts its
|
|
/// pane observes.
|
|
nonisolated enum PassReadiness: Equatable {
|
|
case ready
|
|
case missingKey(providerLabel: String)
|
|
case unknown
|
|
|
|
/// Read each pass surface's provider (readSurface, one task group),
|
|
/// then resolve each DISTINCT provider's credential through the ONE
|
|
/// rail (ProviderCredential — provider key, else the Portal session
|
|
/// key for keyless providers). A surface we can't read maps .unknown
|
|
/// (our own read failure never blocks — the spawn's honest failure row
|
|
/// owns that path); a refused credential maps .missingKey naming the
|
|
/// provider. Nil/empty `base_url` means the provider's default family
|
|
/// (the family the session key is allowed to ride).
|
|
static func refresh(
|
|
writer: any SettingsWriting,
|
|
portalAuthPath: String,
|
|
) async -> [PassKind: PassReadiness] {
|
|
let surfaces = [ProfileSurface.pass1, .pass2]
|
|
var reads: [ProfileSurface: (config: SurfaceModelConfig, baseURL: String?)] = [:]
|
|
await withTaskGroup(of: (ProfileSurface, (config: SurfaceModelConfig, baseURL: String?)?).self) { group in
|
|
for surface in surfaces {
|
|
group.addTask { await (surface, try? writer.readSurface(surface)) }
|
|
}
|
|
for await (surface, read) in group {
|
|
if let read {
|
|
reads[surface] = read
|
|
}
|
|
}
|
|
}
|
|
var envKeys: [ModelProvider: String] = [:]
|
|
for provider in Set(reads.values.map(\.config.provider)) {
|
|
envKeys[provider] = await (try? writer.readProviderKey(provider: provider)) ?? ""
|
|
}
|
|
var verdicts: [PassKind: PassReadiness] = [:]
|
|
for surface in surfaces {
|
|
let kind: PassKind = surface == .pass1 ? .pass1 : .pass2
|
|
guard let read = reads[surface] else {
|
|
verdicts[kind] = .unknown
|
|
continue
|
|
}
|
|
let provider = read.config.provider
|
|
let endpoint = read.baseURL.flatMap { $0.isEmpty ? nil : $0 } ?? provider.defaultEndpoint
|
|
switch await ProviderCredential.resolve(
|
|
provider: provider,
|
|
envKey: envKeys[provider] ?? "",
|
|
endpoint: endpoint,
|
|
portalAuthPath: portalAuthPath,
|
|
) {
|
|
case .key:
|
|
verdicts[kind] = .ready
|
|
case .refused:
|
|
verdicts[kind] = .missingKey(providerLabel: provider.label)
|
|
}
|
|
}
|
|
return verdicts
|
|
}
|
|
}
|