feat(settings): add Nous Portal provider (#175)
CI / ci (push) Canceled after 0s

Settings gains hermes' `nous` slug as a fourth provider on every
surface and the Provider Keys page — endpoint
https://inference-api.nousresearch.com/v1, NOUS_API_KEY, the
5-level OpenAI-compatible effort ladder, switch flagship
anthropic/claude-sonnet-5 (live-probed: the portal's docs-listed
Hermes-4 ids 404 — the inference API serves the OpenRouter catalog,
so the switch keeps the app's sonnet posture billed through Nous).
The probe speaks plain OpenAI chat-completions; an unkeyed test
borrows the shared Portal session's agent_key (the engine's own
credential — hermes' nous runtime is OAuth-only, and a portal key
and subscription bill the same account credits), gated to the
official https endpoint so the implicit credential never rides a
user-edited URL. Pass readiness rides the same fallback, so a
logged-in machine runs passes with no key. Suite 635.

Closes #175
This commit is contained in:
AlexKucera committed 2026-11-05 15:59:41 +01:00
1 parent d305f822aa
commit b2db859887
15 files changed
+410 -30

No files matched your search

+21 -10
View File
@@ -113,6 +113,11 @@ nonisolated enum ProviderProbe {
case .anthropic:
body["messages"] = [user]
body["max_tokens"] = Self.probeTokenCap // required
case .nous:
// #175: plain OpenAI chat-completions — live-probed, the portal
// router takes no thinking knobs and answers finish=stop.
body["messages"] = [user]
body["max_tokens"] = Self.probeTokenCap
}
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
applyAuth(&request, provider: config.provider, key: config.apiKey)
@@ -135,17 +140,18 @@ nonisolated enum ProviderProbe {
/// z.ai's endpoint carries its version segment already (`…/paas/v4`);
/// Anthropic's base is bare and appends `/v1`; OpenAI speaks the
/// Responses API (`/v1/responses`, 2026-10-28 maintainer correction —
/// chat-completions is the retired path). 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).
/// 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).
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: "/chat/completions"
case .zai, .nous: "/chat/completions"
}
return httpURL(base + path)
}
@@ -164,10 +170,12 @@ nonisolated enum ProviderProbe {
}
/// Bearer everywhere except Anthropic: `x-api-key` + a pinned
/// `anthropic-version` (factsheet §2.1 — never send none).
/// `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).
static func applyAuth(_ request: inout URLRequest, provider: ModelProvider, key: String) {
switch provider {
case .zai, .openaiAPI:
case .zai, .openaiAPI, .nous:
request.setValue("Bearer \(key)", forHTTPHeaderField: "Authorization")
case .anthropic:
request.setValue(key, forHTTPHeaderField: "x-api-key")
@@ -218,7 +226,10 @@ nonisolated enum ProviderProbe {
let envelope = (root["error"] as? [String: Any]) ?? [:]
let code = envelope["code"] as? String ?? ""
let type = envelope["type"] as? String ?? ""
let message = (envelope["message"] as? String) ?? "HTTP \(status)"
// #175: the portal's envelope is bare {status, message} — no error
// object — so fall back to the root message (existing providers
// always carry an error object; the fallback is invisible to them).
let message = (envelope["message"] as? String) ?? (root["message"] as? String) ?? "HTTP \(status)"
let requestID = (root["request_id"] as? String).map { " (request \($0))" } ?? ""
if provider == .zai, code == "1113" {
@@ -247,7 +258,7 @@ nonisolated enum ProviderProbe {
switch provider {
case .anthropic: (text, finish) = anthropicStream(events)
case .openaiAPI: (text, finish) = responsesStream(events)
case .zai: (text, finish) = chatCompletionsStream(events)
case .zai, .nous: (text, finish) = chatCompletionsStream(events)
}
if !text.isEmpty {
return .works(latencyMS: latencyMS, modelCount: modelCount)