feat(agent): 添加对持久化子智能体的支持并增强委派管理 添加了持久化子智能体的完整生命周期管理功能,包括创建、更新、删除和查询API接口。 新增了子智能体的JSON-RPC通信协议支持,实现了远程调用和任务管理功能。 同时增强了委派管理器的功能: - 添加了对本地委派、插件委派和本地回退的开关控制 - 实现了持久化子智能体任务的自动检测和本地执行保护 - 增加了对不同委派类型的权限验证机制 修改了智能体注册表以支持插件智能体的条件性包含,并更新了工具注册逻辑以支持可选工具。 BREAKING CHANGE: 委派管理器的构造函数签名已更改,添加了新的控制参数。 ```
77 lines
3.0 KiB
TypeScript
77 lines
3.0 KiB
TypeScript
'use client';
|
|
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { cn } from '@/lib/utils';
|
|
import type { OfficeTaskStatus, OfficeZoneView } from '@/lib/office';
|
|
import { officeTaskStatusLabel } from '@/lib/office';
|
|
|
|
export function OfficeStatusBadge({
|
|
status,
|
|
className,
|
|
}: {
|
|
status: OfficeTaskStatus;
|
|
className?: string;
|
|
}) {
|
|
return (
|
|
<Badge
|
|
variant="outline"
|
|
className={cn(
|
|
'border text-[11px]',
|
|
status === 'done' && 'border-emerald-500/30 bg-emerald-500/10 text-emerald-700',
|
|
status === 'running' && 'border-sky-500/30 bg-sky-500/10 text-sky-700',
|
|
status === 'waiting' && 'border-amber-500/30 bg-amber-500/10 text-amber-700',
|
|
status === 'blocked' && 'border-orange-500/30 bg-orange-500/10 text-orange-700',
|
|
status === 'queued' && 'border-slate-500/30 bg-slate-500/10 text-slate-700',
|
|
status === 'error' && 'border-rose-500/30 bg-rose-500/10 text-rose-700',
|
|
status === 'cancelled' && 'border-zinc-500/30 bg-zinc-500/10 text-zinc-700',
|
|
className
|
|
)}
|
|
>
|
|
{officeTaskStatusLabel(status)}
|
|
</Badge>
|
|
);
|
|
}
|
|
|
|
export function formatOfficeTime(value?: string | null): string {
|
|
if (!value) return '-';
|
|
const date = new Date(value);
|
|
if (Number.isNaN(date.getTime())) return value;
|
|
return new Intl.DateTimeFormat('zh-CN', {
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
}).format(date);
|
|
}
|
|
|
|
export function formatOfficeDuration(durationMs: number | null): string {
|
|
if (durationMs === null || durationMs < 0) return '-';
|
|
if (durationMs < 1000) return '<1s';
|
|
|
|
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 `${hours}h ${minutes}m`;
|
|
if (minutes > 0) return `${minutes}m ${remainingSeconds}s`;
|
|
return `${remainingSeconds}s`;
|
|
}
|
|
|
|
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)));
|
|
}
|
|
|
|
export function zonePanelClassName(zone: OfficeZoneView): string {
|
|
return cn(
|
|
'relative min-h-[220px] overflow-hidden rounded-2xl border p-4 shadow-sm',
|
|
'before:pointer-events-none before:absolute before:inset-0 before:bg-[radial-gradient(circle_at_top_left,rgba(255,255,255,0.9),transparent_40%)]',
|
|
zone.tone === 'info' && 'border-sky-200 bg-[linear-gradient(180deg,rgba(240,249,255,0.95),rgba(224,242,254,0.7))]',
|
|
zone.tone === 'warn' && 'border-amber-200 bg-[linear-gradient(180deg,rgba(255,251,235,0.95),rgba(254,243,199,0.72))]',
|
|
zone.tone === 'danger' && 'border-rose-200 bg-[linear-gradient(180deg,rgba(255,241,242,0.96),rgba(255,228,230,0.76))]',
|
|
zone.tone === 'success' && 'border-emerald-200 bg-[linear-gradient(180deg,rgba(236,253,245,0.96),rgba(209,250,229,0.74))]',
|
|
zone.tone === 'neutral' && 'border-border bg-card'
|
|
);
|
|
}
|