feat(engine): 优化智能体循环中的助手消息处理逻辑 - 在没有工具调用时才添加助手消息到上下文 - 确保工具调用响应正确添加到消息上下文中 - 修复了消息构建的条件逻辑 fix(cron): 改进定时任务调度的时间解析功能 - 添加正则表达式导入用于时间显示解析 - 实现从显示文本中提取毫秒间隔的功能 - 增强整数转换的安全性,避免类型错误 - 优化定时任务配置的解析逻辑 feat(outlook): 增强Outlook集成的功能和稳定性 - 将默认超时时间从10秒增加到180秒 - 为状态检查函数添加可选的验证参数 - 串行执行邮件概览获取操作而非并行 - 改进连接状态验证逻辑 feat(channel): 添加设备名称作为会话标识的选项 - 为终端WebSocket适配器添加新的配置选项 - 实现基于设备名称生成会话对等ID的功能 - 记录原始对等ID和设备名称的元数据 - 支持从设备名称创建会话对等ID feat(skills): 完善技能学习评估系统和进度跟踪 - 在应用启动时自动调度待评估的技能草稿 - 为技能评估工作创建独立的循环工厂 - 实现异步技能评估任务的取消和清理机制 - 添加技能评估进度报告和状态跟踪功能 - 扩展会话列表API以包含更多详细信息 - 防止对不存在的会话进行操作 - 优化技能草稿提交和评估的业务逻辑 perf(skills): 提升技能评估的并发性能 - 实现并行技能案例评估以提高效率 - 添加最大并行案例数的环境变量控制 - 实现实时评估进度更新和回调机制 - 优化评估过程中的资源管理和同步 refactor(services): 创建隔离的智能体循环实例 - 添加创建独立智能体循环的工厂方法 - 确保新循环继承运行时服务配置 - 支持技能评估等需要隔离环境的场景 ```
113 lines
5.1 KiB
TypeScript
113 lines
5.1 KiB
TypeScript
'use client';
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
import Link from 'next/link';
|
|
import { AlertCircle, Bell, Clock3, Loader2, RefreshCw, ArrowRight } from 'lucide-react';
|
|
|
|
import { listNotifications } from '@/lib/api';
|
|
import type { NotificationRun } from '@/types';
|
|
import { pickAppText } from '@/lib/i18n/core';
|
|
import { useAppI18n } from '@/lib/i18n/provider';
|
|
import { scheduleNotificationRefresh } from '@/lib/notification-runtime';
|
|
import { containedLongTextClass } from '@/lib/text-wrapping';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Card, CardContent } from '@/components/ui/card';
|
|
|
|
export default function NotificationsPage() {
|
|
const { locale } = useAppI18n();
|
|
const [items, setItems] = useState<NotificationRun[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const load = React.useCallback(async (background = false) => {
|
|
if (!background) setLoading(true);
|
|
setError(null);
|
|
try {
|
|
setItems(await listNotifications());
|
|
} catch (err: any) {
|
|
setError(err.message || pickAppText(locale, '加载通知失败', 'Failed to load notifications'));
|
|
} finally {
|
|
if (!background) setLoading(false);
|
|
}
|
|
}, [locale]);
|
|
|
|
useEffect(() => {
|
|
void load();
|
|
return scheduleNotificationRefresh(() => load(true));
|
|
}, [load]);
|
|
|
|
const formatTime = (value?: string | null) => {
|
|
if (!value) return '-';
|
|
return new Date(value).toLocaleString(locale, { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });
|
|
};
|
|
|
|
return (
|
|
<main className="mx-auto flex h-[calc(100vh-4rem)] max-w-6xl flex-col px-4 py-6 sm:px-6 sm:py-8">
|
|
<div className="mb-6 flex flex-wrap items-center justify-between gap-3">
|
|
<div className="min-w-0">
|
|
<h1 className="flex items-center gap-2 text-2xl font-semibold tracking-tight">
|
|
<Bell className="h-5 w-5" />
|
|
{pickAppText(locale, '通知', 'Notifications')}
|
|
</h1>
|
|
<p className="mt-1 max-w-2xl text-sm text-muted-foreground">
|
|
{pickAppText(locale, '定时任务生成的日报、提醒和总结会固定出现在这里。', 'Scheduled reports, reminders, and summaries appear here.')}
|
|
</p>
|
|
</div>
|
|
<Button onClick={() => void load()} variant="outline" size="sm" className="h-11">
|
|
<RefreshCw className="mr-2 h-4 w-4" />
|
|
{pickAppText(locale, '刷新', 'Refresh')}
|
|
</Button>
|
|
</div>
|
|
|
|
{error && (
|
|
<Card className="mb-4 border-destructive">
|
|
<CardContent className="flex items-center gap-2 pt-6 text-sm text-destructive">
|
|
<AlertCircle className="h-4 w-4" />
|
|
{error}
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
<div className="min-h-0 flex-1 overflow-auto rounded-lg border border-[#E6E1DE] bg-white">
|
|
{loading ? (
|
|
<div className="flex h-full items-center justify-center text-muted-foreground">
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
{pickAppText(locale, '加载中', 'Loading')}
|
|
</div>
|
|
) : items.length === 0 ? (
|
|
<div className="flex h-full flex-col items-center justify-center text-muted-foreground">
|
|
<Bell className="mb-3 h-10 w-10 opacity-40" />
|
|
<p className="font-medium">{pickAppText(locale, '暂无通知', 'No notifications yet')}</p>
|
|
</div>
|
|
) : (
|
|
<div className="divide-y divide-[#E6E1DE]">
|
|
{items.map((item) => (
|
|
<Link
|
|
key={item.scheduled_run_id}
|
|
href={`/notifications/${encodeURIComponent(item.scheduled_run_id)}`}
|
|
className="grid min-w-0 gap-3 px-4 py-4 transition-colors hover:bg-[#F7F6F5] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset sm:px-5 md:grid-cols-[minmax(0,1fr)_180px_110px_24px]"
|
|
>
|
|
<div className="min-w-0">
|
|
<div className="flex min-w-0 items-center gap-2">
|
|
<span className={`min-w-0 flex-1 font-medium ${containedLongTextClass}`}>{item.title || item.job_name}</span>
|
|
{item.engaged && <Badge variant="secondary" className="shrink-0">{pickAppText(locale, '已接入 Task', 'Task linked')}</Badge>}
|
|
{item.status === 'error' && <Badge variant="destructive" className="shrink-0">{pickAppText(locale, '错误', 'Error')}</Badge>}
|
|
</div>
|
|
<p className={`mt-1 line-clamp-2 text-sm text-muted-foreground ${containedLongTextClass}`}>{item.output || item.message}</p>
|
|
</div>
|
|
<div className="flex min-w-0 items-center gap-2 text-sm text-muted-foreground">
|
|
<Clock3 className="h-4 w-4" />
|
|
{formatTime(item.started_at)}
|
|
</div>
|
|
<div className={`text-sm text-muted-foreground ${containedLongTextClass}`}>{item.job_name}</div>
|
|
<ArrowRight className="hidden h-4 w-4 self-center text-muted-foreground md:block" />
|
|
</Link>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|