run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
final cfg = ai.AiConfigIo.load(
path: omnyServerAiConfigPath(argResults!['path'] as String?),
);
if (cfg == null) {
throw CliError(
'AI is not configured. Set a key (ANTHROPIC_API_KEY / OPENAI_API_KEY / '
'GEMINI_API_KEY) or run: omnyserver ai config --help',
);
}
final models = <String>{
cfg.modelFor(ai.AgentPhase.planning),
cfg.modelFor(ai.AgentPhase.executing),
}.toList();
stdout.writeln(
'Validating ${cfg.provider.wireName} with ${models.length} model(s)…',
);
final provider = ai.providerFor(cfg, http.Client());
try {
final results = await ai.validateModels(provider, models);
var anyFail = false;
for (final r in results) {
if (r.ok) {
final ms = r.latencyMs == null ? '' : ' (${r.latencyMs} ms)';
stdout.writeln(' ✓ ${r.model}$ms');
} else {
anyFail = true;
stdout.writeln(' ✗ ${r.model}: ${r.error}');
}
}
if (anyFail) throw CliError('validation failed for one or more models.');
stdout.writeln('OK — key and model(s) valid.');
} finally {
provider.close();
}
}