Line data Source code
1 : import { isCloud } from '@/platform/distribution/types'
2 : import type { SystemStats } from '@comfyorg/api-client/types'
3 : import { formatCommitHash, formatSize } from '@/utils/formatUtil'
4 :
5 : const frontendCommit = __COMFYUI_FRONTEND_COMMIT__
6 :
7 : type SystemInfoKey = keyof SystemStats['system']
8 :
9 : export type SystemStatsColumn = Readonly<{
10 : field: SystemInfoKey
11 : headerKey: string
12 : format?: (value: string) => string
13 : formatNumber?: (value: number) => string
14 : getValue?: () => string
15 : }>
16 :
17 : const localColumns = [
18 : { field: 'argv', headerKey: 'g.systemStatsArguments' },
19 : { field: 'embedded_python', headerKey: 'g.systemStatsEmbeddedPython' },
20 : {
21 : field: 'installed_templates_version',
22 : headerKey: 'g.systemStatsTemplatesVersion'
23 : },
24 : { field: 'os', headerKey: 'g.systemStatsOS' },
25 : { field: 'python_version', headerKey: 'g.systemStatsPythonVersion' },
26 : { field: 'pytorch_version', headerKey: 'g.systemStatsPyTorchVersion' },
27 : {
28 : field: 'ram_free',
29 : headerKey: 'g.systemStatsRAMFree',
30 : formatNumber: formatSize
31 : },
32 : {
33 : field: 'ram_total',
34 : headerKey: 'g.systemStatsRAMTotal',
35 : formatNumber: formatSize
36 : }
37 : ] as const satisfies readonly SystemStatsColumn[]
38 :
39 : const cloudColumns = [
40 : { field: 'cloud_version', headerKey: 'g.systemStatsCloudVersion' },
41 : {
42 : field: 'comfyui_frontend_version',
43 : headerKey: 'g.systemStatsFrontendVersion',
44 : getValue: () => frontendCommit,
45 : format: formatCommitHash
46 : },
47 : {
48 : field: 'comfyui_version',
49 : headerKey: 'g.systemStatsComfyUIVersion',
50 : format: formatCommitHash
51 : },
52 : {
53 : field: 'workflow_templates_version',
54 : headerKey: 'g.systemStatsTemplatesVersion'
55 : }
56 : ] as const satisfies readonly SystemStatsColumn[]
57 :
58 4 : export const systemStatsColumns: readonly SystemStatsColumn[] = isCloud
59 : ? cloudColumns
60 : : localColumns
61 :
62 40 : export function getColumnDisplayValue(
63 : stats: SystemStats,
64 : column: SystemStatsColumn
65 : ): string | number | boolean | undefined {
66 40 : const systemInfo = {
67 : ...stats.system,
68 : argv: stats.system.argv.join(' ')
69 : }
70 40 : const value = column.getValue ? column.getValue() : systemInfo[column.field]
71 40 : if (column.formatNumber && typeof value === 'number') {
72 10 : return column.formatNumber(value)
73 : }
74 40 : if (column.format && typeof value === 'string') {
75 0 : return column.format(value)
76 : }
77 40 : if (Array.isArray(value)) return undefined
78 30 : return value
79 : }
|