diff --git a/src/commands/models/scan.ts b/src/commands/models/scan.ts index ae4ff1a1b52..c6d44d50df5 100644 --- a/src/commands/models/scan.ts +++ b/src/commands/models/scan.ts @@ -50,19 +50,7 @@ function sortScanResults(results: ModelScanResult[]): ModelScanResult[] { return aToolLatency - bToolLatency; } - const aCtx = a.contextLength ?? 0; - const bCtx = b.contextLength ?? 0; - if (aCtx !== bCtx) { - return bCtx - aCtx; - } - - const aParams = a.inferredParamB ?? 0; - const bParams = b.inferredParamB ?? 0; - if (aParams !== bParams) { - return bParams - aParams; - } - - return a.modelRef.localeCompare(b.modelRef); + return compareScanMetadata(a, b); }); } @@ -74,22 +62,26 @@ function sortImageResults(results: ModelScanResult[]): ModelScanResult[] { return aLatency - bLatency; } - const aCtx = a.contextLength ?? 0; - const bCtx = b.contextLength ?? 0; - if (aCtx !== bCtx) { - return bCtx - aCtx; - } - - const aParams = a.inferredParamB ?? 0; - const bParams = b.inferredParamB ?? 0; - if (aParams !== bParams) { - return bParams - aParams; - } - - return a.modelRef.localeCompare(b.modelRef); + return compareScanMetadata(a, b); }); } +function compareScanMetadata(a: ModelScanResult, b: ModelScanResult): number { + const aCtx = a.contextLength ?? 0; + const bCtx = b.contextLength ?? 0; + if (aCtx !== bCtx) { + return bCtx - aCtx; + } + + const aParams = a.inferredParamB ?? 0; + const bParams = b.inferredParamB ?? 0; + if (aParams !== bParams) { + return bParams - aParams; + } + + return a.modelRef.localeCompare(b.modelRef); +} + function buildScanHint(result: ModelScanResult): string { const toolLabel = result.tool.ok ? `tool ${formatMs(result.tool.latencyMs)}` : "tool fail"; const imageLabel = result.image.skipped