Path: blob/main/src/vs/workbench/contrib/chat/common/chatProgressFormatting.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { localize } from '../../../../nls.js';67/**8* Format a millisecond duration as a human-readable elapsed time string.9* Examples: "0s", "45s", "1m 23s", "12m 5s"10*/11export function formatElapsedTime(ms: number): string {12const totalSeconds = Math.floor(ms / 1000);13if (totalSeconds < 60) {14return localize('seconds', "{0}s", totalSeconds);15}16const minutes = Math.floor(totalSeconds / 60);17const seconds = totalSeconds % 60;18return localize('minutesSeconds', "{0}m {1}s", minutes, seconds);19}2021/**22* Format a token count as a human-readable string.23* Examples: "500", "1.2k", "1.5m"24*/25export function formatTokenCount(count: number): string {26if (count >= 1_000_000) {27return `${(count / 1_000_000).toFixed(1)}m`;28} else if (count >= 1000) {29const value = count / 1000;30if (value >= 10) {31const roundedValue = value.toFixed(0);32if (roundedValue === '1000') {33return `${(count / 1_000_000).toFixed(1)}m`;34}35return `${roundedValue}k`;36}37return `${value.toFixed(1)}k`;38}39return count.toString();40}414243