移除了所有Hermes相关的命名引用,包括: - 从.gitignore中清理相关构建缓存文件 - 将README中的beaver-home路径配置更新 - 完善backend/README.md文档说明Beaver后端主线实现 - 移除Hermes风格的相关注释和兼容性代码 - 清理nanobot环境变量兼容性处理 - 删除技能迁移和服务迁移相关功能代码 - 更新测试用例中相关命名和函数名 BREAKING CHANGE: 移除了Hermes迁移相关API和CLI命令,不再支持nanobot环境变量兼容性
68 lines
2.5 KiB
TypeScript
68 lines
2.5 KiB
TypeScript
'use client';
|
|
|
|
import { useAppI18n } from '@/lib/i18n/provider';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { cn } from '@/lib/utils';
|
|
import type { TaskRuntimeStatus } from '@/lib/task-runtime';
|
|
import { taskRuntimeStatusLabel } from '@/lib/task-runtime';
|
|
|
|
export function TaskRuntimeStatusBadge({
|
|
status,
|
|
className,
|
|
}: {
|
|
status: TaskRuntimeStatus;
|
|
className?: string;
|
|
}) {
|
|
const { locale } = useAppI18n();
|
|
|
|
return (
|
|
<Badge
|
|
variant="outline"
|
|
className={cn(
|
|
'border text-[11px]',
|
|
status === 'done' && 'border-[#B7C2B5] bg-[#E3E8E2] text-[#657162]',
|
|
status === 'running' && 'border-[#BCC4CE] bg-[#E4E7EB] text-[#697281]',
|
|
status === 'waiting' && 'border-[#B8AEA8] bg-[#E7E2DE] text-[#5F5550]',
|
|
status === 'blocked' && 'border-[#B8AEA8] bg-[#E7E2DE] text-[#5F5550]',
|
|
status === 'queued' && 'border-[#D8D2CE] bg-[#ECE8E5] text-[#4F4642]',
|
|
status === 'error' && 'border-[#B8AEA8] bg-[#E7E2DE] text-[#342E2B]',
|
|
status === 'cancelled' && 'border-[#D8D2CE] bg-[#ECE8E5] text-[#6A5E58]',
|
|
className
|
|
)}
|
|
>
|
|
{taskRuntimeStatusLabel(status, locale)}
|
|
</Badge>
|
|
);
|
|
}
|
|
|
|
export function formatTaskRuntimeTime(value?: string | null, locale: 'zh-CN' | 'en-US' = 'zh-CN'): string {
|
|
if (!value) return '-';
|
|
const date = new Date(value);
|
|
if (Number.isNaN(date.getTime())) return value;
|
|
return new Intl.DateTimeFormat(locale, {
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
}).format(date);
|
|
}
|
|
|
|
export function formatTaskRuntimeDuration(durationMs: number | null, locale: 'zh-CN' | 'en-US' = 'zh-CN'): string {
|
|
if (durationMs === null || durationMs < 0) return '-';
|
|
if (durationMs < 1000) return locale === 'en-US' ? '<1s' : '<1秒';
|
|
|
|
const seconds = Math.floor(durationMs / 1000);
|
|
const hours = Math.floor(seconds / 3600);
|
|
const minutes = Math.floor((seconds % 3600) / 60);
|
|
const remainingSeconds = seconds % 60;
|
|
|
|
if (hours > 0) return locale === 'en-US' ? `${hours}h ${minutes}m` : `${hours}小时 ${minutes}分`;
|
|
if (minutes > 0) return locale === 'en-US' ? `${minutes}m ${remainingSeconds}s` : `${minutes}分 ${remainingSeconds}秒`;
|
|
return locale === 'en-US' ? `${remainingSeconds}s` : `${remainingSeconds}秒`;
|
|
}
|
|
|
|
export function progressPercent(value: number | null, max: number | null): number {
|
|
if (value === null || max === null || max <= 0) return 0;
|
|
return Math.max(0, Math.min(100, Math.round((value / max) * 100)));
|
|
}
|