buildCliDefaultModel function
Builds the legacy single Model the fah executable runs when no roles
are configured (--provider/--model/--base-url flags).
Resolves through resolveCliProviderSpec — every catalog name and kind
builds; an id no version knows throws ConfigException (direct API
callers get the loud error, the boot config boundary degrades it).
maxTokens resolves like buildCatalogModel: ceiling table
(resolveModelMaxOutputTokens) first, provider spec default on a miss.
Implementation
Model buildCliDefaultModel(
String providerKind, {
String? modelId,
String? baseUrl,
List<String>? input,
String? thinkingLevel,
String? authHeader,
}) {
final spec = resolveCliProviderSpec(providerKind, baseUrl: baseUrl);
if (spec == null) {
throw ConfigException('unknown provider: $providerKind');
}
validateAuthHeaderDialect(authHeader, spec, 'provider "$providerKind"');
final id = modelId;
if (id == null) {
// No provider has a default model — the choice is always explicit.
throw ConfigException('provider "$providerKind" requires --model <id>');
}
final maxTokens =
resolveModelMaxOutputTokens(id, api: spec.api) ?? spec.maxTokens;
return Model(
id: id,
name: id,
api: spec.api,
provider: spec.name,
baseUrl: baseUrl ?? spec.defaultBaseUrl,
reasoning: spec.reasoning,
input: input ?? spec.input,
// The FA_PROVIDER_* preconfig level rides the fallback/default model
// when no roles chain pins it (issue #734 rework: the boot notice must
// never name a level the booted model does not carry).
thinkingLevel: thinkingLevel,
contextWindow: spec.contextWindow,
maxTokens: maxTokens,
// Folder-state restores adopt the matching saved entry's authHeader
// (issue #964) — a restored gateway endpoint without its header 401s.
authHeader: authHeader,
);
}