feat: add token breakdown helpers
This commit is contained in:
35
lib/token-breakdown.ts
Normal file
35
lib/token-breakdown.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { sortDetailBreakdown, type DetailBreakdownItem, type DetailBreakdownSortKey } from "./detail-sort";
|
||||
|
||||
export interface TokenBreakdownItem extends DetailBreakdownItem {
|
||||
models: DetailBreakdownItem[];
|
||||
}
|
||||
|
||||
export type TokenBreakdownSortKey = DetailBreakdownSortKey;
|
||||
|
||||
export function sortTokenBreakdown(
|
||||
items: TokenBreakdownItem[],
|
||||
sortKey: TokenBreakdownSortKey,
|
||||
sortAsc: boolean
|
||||
): TokenBreakdownItem[] {
|
||||
return sortDetailBreakdown(items, sortKey, sortAsc);
|
||||
}
|
||||
|
||||
export function getTokenDisplayName(name: string, unnamedLabel: string): string {
|
||||
return name === "" ? unnamedLabel : name;
|
||||
}
|
||||
|
||||
export function getTokenRowKey(name: string): string {
|
||||
return name === "" ? "__unnamed_token__" : name;
|
||||
}
|
||||
|
||||
export function shouldShowTokenTab(detailType: string): boolean {
|
||||
return detailType === "user";
|
||||
}
|
||||
|
||||
export function getSharePercent(part: number, total: number): number {
|
||||
return total > 0 ? (part / total) * 100 : 0;
|
||||
}
|
||||
|
||||
export function getPrimaryModelNames(models: DetailBreakdownItem[], limit = 3): string {
|
||||
return models.slice(0, limit).map((model) => model.name || "(unknown)").join(", ");
|
||||
}
|
||||
Reference in New Issue
Block a user