refactor(settings): provider facts as data
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
This commit is contained in:
AlexKucera committed 2026-11-10 10:58:29 +01:00
1 parent 218e2db397
commit f49e4b6ca0
15 files changed
+506 -184

No files matched your search

+18 -22
View File
@@ -142,24 +142,19 @@ nonisolated enum ProviderProbe {
/// Responses API (`/v1/responses`, 2026-10-28 maintainer correction —
/// chat-completions is the retired path). Nous (#175, live-probed
/// 2026-11-05) is plain OpenAI chat-completions on a versioned base.
/// A trailing slash on a hand-edited endpoint never doubles up. A
/// non-URL endpoint is nil (URL(string:) happily percent-encodes "not a
/// url" — the scheme check is what actually rejects garbage; probe
/// reports unreachable, never traps).
/// #181: the paths live on the descriptor's dialect — a trailing slash
/// on a hand-edited endpoint never doubles up. A non-URL endpoint is
/// nil (URL(string:) happily percent-encodes "not a url" — the scheme
/// check is what actually rejects garbage; probe reports unreachable,
/// never traps).
static func chatURL(for provider: ModelProvider, endpoint: String) -> URL? {
let base = endpoint.hasSuffix("/") ? String(endpoint.dropLast()) : endpoint
let path = switch provider {
case .anthropic: "/v1/messages"
case .openaiAPI: "/responses"
case .zai, .nous: "/chat/completions"
}
return httpURL(base + path)
let base = ModelProvider.trimmedEndpoint(endpoint)
return httpURL(base + provider.dialect.chatPath)
}
static func modelsURL(for provider: ModelProvider, endpoint: String) -> URL? {
let base = endpoint.hasSuffix("/") ? String(endpoint.dropLast()) : endpoint
let path = provider == .anthropic ? "/v1/models" : "/models"
return httpURL(base + path)
let base = ModelProvider.trimmedEndpoint(endpoint)
return httpURL(base + provider.dialect.modelsPath)
}
private static func httpURL(_ string: String) -> URL? {
@@ -172,14 +167,15 @@ nonisolated enum ProviderProbe {
/// Bearer everywhere except Anthropic: `x-api-key` + a pinned
/// `anthropic-version` (factsheet §2.1 — never send none). Nous rides
/// Bearer too — the portal accepts the session agent_key and an API
/// key interchangeably (#175).
/// key interchangeably (#175). #181: the shape keys off the
/// descriptor's auth mode.
static func applyAuth(_ request: inout URLRequest, provider: ModelProvider, key: String) {
switch provider {
case .zai, .openaiAPI, .nous:
switch provider.authMode {
case .bearer:
request.setValue("Bearer \(key)", forHTTPHeaderField: "Authorization")
case .anthropic:
case let .headerKey(version):
request.setValue(key, forHTTPHeaderField: "x-api-key")
request.setValue("2023-06-01", forHTTPHeaderField: "anthropic-version")
request.setValue(version, forHTTPHeaderField: "anthropic-version")
}
}
@@ -255,10 +251,10 @@ nonisolated enum ProviderProbe {
return failure
}
let (text, finish): (String, String?)
switch provider {
switch provider.dialect {
case .anthropic: (text, finish) = anthropicStream(events)
case .openaiAPI: (text, finish) = responsesStream(events)
case .zai, .nous: (text, finish) = chatCompletionsStream(events)
case .responses: (text, finish) = responsesStream(events)
case .chatCompletions: (text, finish) = chatCompletionsStream(events)
}
if !text.isEmpty {
return .works(latencyMS: latencyMS, modelCount: modelCount)