Files
beaver_project/app-instance/frontend/app/(app)/notifications/[scheduledRunId]/page.tsx
steven_li a27560102b feat(task): 添加任务修订功能和超时处理机制
添加了 `revise_task` 路由动作类型,允许用户修改、纠正或重新执行最新活动任务结果。
实现了工具失败指导原则,防止相同类别工具重复失败。
为任务规划器添加了超时处理机制,避免长时间等待。

BREAKING CHANGE: 任务路由逻辑已更新,新增 `revise_task` 动作类型。

fix(api): 修复任务详情API返回完整流程投影

修复了任务详情API端点,现在会包含过滤后的流程运行、事件和工件信息,
并确保时间戳字段正确序列化。

refactor(engine): 优化任务技能解析器摘要节点处理

改进了任务技能解析器对摘要节点的处理逻辑,对于仅依赖文本生成功能的摘要节
点不再分配具体技能,直接使用依赖项输出进行汇总。

test: 增加任务修订和超时处理测试用例

添加了测试用例验证任务修订输入记录反馈、超时回退到单模式以及
摘要节点技能解析等新功能。
2026-05-21 16:40:44 +08:00

210 lines
8.5 KiB
TypeScript

'use client';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import Link from 'next/link';
import { useParams } from 'next/navigation';
import { ArrowLeft, Check, Loader2, RefreshCw, Send, Settings2 } from 'lucide-react';
import { getNotification, sendMessage } from '@/lib/api';
import type { ChatMessage, NotificationDetail } from '@/types';
import { pickAppText } from '@/lib/i18n/core';
import { useAppI18n } from '@/lib/i18n/provider';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { ChatWorkbench } from '@/components/chat-workbench/ChatWorkbench';
type ReplyIntent = 'revise_once' | 'update_future';
export default function NotificationDetailPage() {
const { locale } = useAppI18n();
const params = useParams<{ scheduledRunId: string }>();
const scheduledRunId = decodeURIComponent(params.scheduledRunId);
const [detail, setDetail] = useState<NotificationDetail | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [intent, setIntent] = useState<ReplyIntent | null>(null);
const [input, setInput] = useState('');
const [submitting, setSubmitting] = useState(false);
const messagesEndRef = useRef<HTMLDivElement>(null);
const viewportRef = useRef<HTMLDivElement>(null);
const load = React.useCallback(async () => {
setLoading(true);
setError(null);
try {
setDetail(await getNotification(scheduledRunId));
} catch (err: any) {
setError(err.message || pickAppText(locale, '加载通知详情失败', 'Failed to load notification detail'));
} finally {
setLoading(false);
}
}, [locale, scheduledRunId]);
useEffect(() => {
void load();
}, [load]);
const messages = useMemo<ChatMessage[]>(() => {
if (!detail) return [];
const runId = detail.run_id;
const scoped = detail.detail.messages.filter((message) => !runId || message.run_id === runId || message.scheduled_run_id === detail.scheduled_run_id);
if (scoped.length > 0) return scoped;
return [
{ role: 'user', content: detail.message, timestamp: detail.started_at || undefined },
{ role: 'assistant', content: detail.output || detail.error || '', timestamp: detail.finished_at || detail.started_at || undefined, run_id: detail.run_id || undefined, task_id: detail.task_id || null },
];
}, [detail]);
const formatTime = (value?: string | null) => {
if (!value) return '-';
return new Date(value).toLocaleString(locale);
};
const submitReply = async () => {
if (!detail || !intent || !input.trim() || submitting) return;
setSubmitting(true);
setError(null);
try {
await sendMessage(
input.trim(),
detail.notification_session_id,
undefined,
{
replyToScheduledRunId: detail.scheduled_run_id,
scheduledReplyIntent: intent,
}
);
setInput('');
await load();
} catch (err: any) {
setError(err.message || pickAppText(locale, '提交修改失败', 'Failed to submit revision'));
} finally {
setSubmitting(false);
}
};
if (loading) {
return (
<main className="flex h-[calc(100vh-4rem)] items-center justify-center text-muted-foreground">
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
{pickAppText(locale, '加载中', 'Loading')}
</main>
);
}
if (!detail) {
return (
<main className="mx-auto max-w-4xl px-6 py-8">
<Link href="/notifications" className="inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground">
<ArrowLeft className="h-4 w-4" />
{pickAppText(locale, '返回通知', 'Back to notifications')}
</Link>
<p className="mt-8 text-destructive">{error || pickAppText(locale, '通知不存在', 'Notification not found')}</p>
</main>
);
}
return (
<main className="flex h-[calc(100vh-4rem)] flex-col bg-background">
<div className="border-b border-[#E6E1DE] bg-[#F7F6F5] px-6 py-4">
<div className="mx-auto flex max-w-6xl flex-wrap items-center justify-between gap-3">
<div className="min-w-0">
<Link href="/notifications" className="mb-2 inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground">
<ArrowLeft className="h-4 w-4" />
{pickAppText(locale, '通知列表', 'Notifications')}
</Link>
<div className="flex min-w-0 flex-wrap items-center gap-2">
<h1 className="truncate text-xl font-semibold">{detail.title || detail.job_name}</h1>
<Badge variant={detail.status === 'error' ? 'destructive' : 'secondary'}>{detail.status}</Badge>
{detail.engaged && <Badge>{pickAppText(locale, '已接入 Task', 'Task linked')}</Badge>}
</div>
<p className="mt-1 text-sm text-muted-foreground">
{pickAppText(locale, '生成时间', 'Generated')}: {formatTime(detail.started_at)}
</p>
</div>
<div className="flex items-center gap-2">
<Button variant="outline" size="sm" onClick={() => void load()}>
<RefreshCw className="mr-2 h-4 w-4" />
{pickAppText(locale, '刷新', 'Refresh')}
</Button>
{detail.task_id && (
<Button asChild size="sm">
<Link href={`/tasks/${encodeURIComponent(detail.task_id)}`}>{pickAppText(locale, '查看任务', 'Open task')}</Link>
</Button>
)}
</div>
</div>
</div>
{error && <div className="mx-auto w-full max-w-6xl px-6 pt-3 text-sm text-destructive">{error}</div>}
<div className="min-h-0 flex-1">
<ChatWorkbench
messages={messages}
isThinking={submitting}
messagesEndRef={messagesEndRef}
messageViewportRef={viewportRef}
processRuns={[]}
processEvents={[]}
processArtifacts={[]}
selectedRunId={null}
onSelectRun={() => {}}
onFeedback={() => {}}
onRequestRevision={() => {}}
/>
</div>
<div className="border-t border-[#E6E1DE] bg-background px-6 py-4">
<div className="mx-auto max-w-5xl">
<div className="mb-2 flex flex-wrap gap-2">
<Button
type="button"
size="sm"
variant={intent === 'revise_once' ? 'default' : 'outline'}
onClick={() => setIntent('revise_once')}
>
<RefreshCw className="mr-2 h-4 w-4" />
{pickAppText(locale, '修改这次', 'Revise this')}
</Button>
<Button
type="button"
size="sm"
variant={intent === 'update_future' ? 'default' : 'outline'}
onClick={() => setIntent('update_future')}
>
<Settings2 className="mr-2 h-4 w-4" />
{pickAppText(locale, '以后按这样', 'Apply going forward')}
</Button>
{detail.engaged && (
<span className="inline-flex items-center gap-1 text-xs text-muted-foreground">
<Check className="h-3.5 w-3.5" />
{pickAppText(locale, '这条通知已经接入 Task', 'This notification is linked to a Task')}
</span>
)}
</div>
{intent && (
<div className="rounded-[20px] border border-[#E6E1DE] bg-white p-3 shadow-[0_6px_18px_rgba(0,0,0,0.06)]">
<textarea
value={input}
onChange={(event) => setInput(event.target.value)}
placeholder={
intent === 'update_future'
? pickAppText(locale, '告诉我以后这类通知要怎么调整...', 'Describe how future notifications should change...')
: pickAppText(locale, '告诉我这次内容要怎么改...', 'Describe how this result should change...')
}
className="block min-h-20 w-full resize-none border-0 bg-transparent px-2 py-1 text-sm leading-6 outline-none"
/>
<div className="flex justify-end">
<Button size="sm" onClick={() => void submitReply()} disabled={!input.trim() || submitting}>
{submitting ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : <Send className="mr-2 h-4 w-4" />}
{pickAppText(locale, '发送', 'Send')}
</Button>
</div>
</div>
)}
</div>
</div>
</main>
);
}