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