mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:38:25 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -80,12 +80,24 @@ export type AuthProbeOptions = {
|
||||
};
|
||||
|
||||
const toStatus = (reason?: string | null): AuthProbeStatus => {
|
||||
if (!reason) return "unknown";
|
||||
if (reason === "auth") return "auth";
|
||||
if (reason === "rate_limit") return "rate_limit";
|
||||
if (reason === "billing") return "billing";
|
||||
if (reason === "timeout") return "timeout";
|
||||
if (reason === "format") return "format";
|
||||
if (!reason) {
|
||||
return "unknown";
|
||||
}
|
||||
if (reason === "auth") {
|
||||
return "auth";
|
||||
}
|
||||
if (reason === "rate_limit") {
|
||||
return "rate_limit";
|
||||
}
|
||||
if (reason === "billing") {
|
||||
return "billing";
|
||||
}
|
||||
if (reason === "timeout") {
|
||||
return "timeout";
|
||||
}
|
||||
if (reason === "format") {
|
||||
return "format";
|
||||
}
|
||||
return "unknown";
|
||||
};
|
||||
|
||||
@@ -93,9 +105,13 @@ function buildCandidateMap(modelCandidates: string[]): Map<string, string[]> {
|
||||
const map = new Map<string, string[]>();
|
||||
for (const raw of modelCandidates) {
|
||||
const parsed = parseModelRef(String(raw ?? ""), DEFAULT_PROVIDER);
|
||||
if (!parsed) continue;
|
||||
if (!parsed) {
|
||||
continue;
|
||||
}
|
||||
const list = map.get(parsed.provider) ?? [];
|
||||
if (!list.includes(parsed.model)) list.push(parsed.model);
|
||||
if (!list.includes(parsed.model)) {
|
||||
list.push(parsed.model);
|
||||
}
|
||||
map.set(parsed.provider, list);
|
||||
}
|
||||
return map;
|
||||
@@ -112,7 +128,9 @@ function selectProbeModel(params: {
|
||||
return { provider, model: direct[0] };
|
||||
}
|
||||
const fromCatalog = catalog.find((entry) => entry.provider === provider);
|
||||
if (fromCatalog) return { provider: fromCatalog.provider, model: fromCatalog.id };
|
||||
if (fromCatalog) {
|
||||
return { provider: fromCatalog.provider, model: fromCatalog.id };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -135,7 +153,9 @@ function buildProbeTargets(params: {
|
||||
|
||||
for (const provider of providers) {
|
||||
const providerKey = normalizeProviderId(provider);
|
||||
if (providerFilterKey && providerKey !== providerFilterKey) continue;
|
||||
if (providerFilterKey && providerKey !== providerFilterKey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const model = selectProbeModel({
|
||||
provider: providerKey,
|
||||
@@ -148,13 +168,17 @@ function buildProbeTargets(params: {
|
||||
const order = store.order;
|
||||
if (order) {
|
||||
for (const [key, value] of Object.entries(order)) {
|
||||
if (normalizeProviderId(key) === providerKey) return value;
|
||||
if (normalizeProviderId(key) === providerKey) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
const cfgOrder = cfg?.auth?.order;
|
||||
if (cfgOrder) {
|
||||
for (const [key, value] of Object.entries(cfgOrder)) {
|
||||
if (normalizeProviderId(key) === providerKey) return value;
|
||||
if (normalizeProviderId(key) === providerKey) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@@ -223,11 +247,15 @@ function buildProbeTargets(params: {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (profileFilter.size > 0) continue;
|
||||
if (profileFilter.size > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const envKey = resolveEnvApiKey(providerKey);
|
||||
const customKey = getCustomProviderApiKey(cfg, providerKey);
|
||||
if (!envKey && !customKey) continue;
|
||||
if (!envKey && !customKey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const label = envKey ? "env" : "models.json";
|
||||
const source = envKey ? "env" : "models.json";
|
||||
@@ -360,7 +388,9 @@ async function runTargetsWithConcurrency(params: {
|
||||
while (true) {
|
||||
const index = cursor;
|
||||
cursor += 1;
|
||||
if (index >= targets.length) return;
|
||||
if (index >= targets.length) {
|
||||
return;
|
||||
}
|
||||
const target = targets[index];
|
||||
onProgress?.({
|
||||
completed,
|
||||
@@ -430,7 +460,9 @@ export async function runAuthProbes(params: {
|
||||
}
|
||||
|
||||
export function formatProbeLatency(latencyMs?: number | null) {
|
||||
if (!latencyMs && latencyMs !== 0) return "-";
|
||||
if (!latencyMs && latencyMs !== 0) {
|
||||
return "-";
|
||||
}
|
||||
return formatMs(latencyMs);
|
||||
}
|
||||
|
||||
@@ -447,7 +479,9 @@ export function groupProbeResults(results: AuthProbeResult[]): Map<string, AuthP
|
||||
export function sortProbeResults(results: AuthProbeResult[]): AuthProbeResult[] {
|
||||
return results.slice().toSorted((a, b) => {
|
||||
const provider = a.provider.localeCompare(b.provider);
|
||||
if (provider !== 0) return provider;
|
||||
if (provider !== 0) {
|
||||
return provider;
|
||||
}
|
||||
const aLabel = a.label || a.profileId || "";
|
||||
const bLabel = b.label || b.profileId || "";
|
||||
return aLabel.localeCompare(bLabel);
|
||||
@@ -455,6 +489,8 @@ export function sortProbeResults(results: AuthProbeResult[]): AuthProbeResult[]
|
||||
}
|
||||
|
||||
export function describeProbeSummary(summary: AuthProbeSummary): string {
|
||||
if (summary.totalTargets === 0) return "No probe targets.";
|
||||
if (summary.totalTargets === 0) {
|
||||
return "No probe targets.";
|
||||
}
|
||||
return `Probed ${summary.totalTargets} target${summary.totalTargets === 1 ? "" : "s"} in ${formatMs(summary.durationMs)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user