| 1 | /** |
| 2 | * Agent Store - 进度工具 |
| 3 | * 进度计算和状态配置 |
| 4 | */ |
| 5 | |
| 6 | import { BASE_PROGRESS, GENERATING_STATUSES, STATUS_CONFIG } from '../agent.constants' |
| 7 | |
| 8 | /** |
| 9 | * 计算任务进度 |
| 10 | * @param currentProgress 当前进度 |
| 11 | * @param status 状态 |
| 12 | * @param isNewStatus 是否是新状态 |
| 13 | */ |
| 14 | export function calculateProgress( |
| 15 | currentProgress: number, |
| 16 | status: string, |
| 17 | isNewStatus: boolean, |
| 18 | ): number { |
| 19 | if (GENERATING_STATUSES.includes(status) && !isNewStatus) { |
| 20 | // 增加 5%,但不超过 99% |
| 21 | return Math.min(currentProgress + 5, 99) |
| 22 | } |
| 23 | |
| 24 | if (isNewStatus) { |
| 25 | const targetProgress = BASE_PROGRESS[status] |
| 26 | if (targetProgress !== undefined) { |
| 27 | return Math.max(currentProgress, targetProgress) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return currentProgress |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * 获取状态配置 |
| 36 | * @param status 状态 |
| 37 | */ |
| 38 | export function getStatusConfig(status: string) { |
| 39 | return STATUS_CONFIG[status] || { text: status, color: '#333' } |
| 40 | } |
| 41 |