🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(task): support deleting a run from the task topic menu (#18452)
Arvin Xu73ca2a02905f
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex ba6c680b84b..5f5f2d172e2 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -1454,6 +1454,9 @@"taskDetail.topicDrawer.untitled": "Untitled","taskDetail.topicMenu.copyId": "Copy Topic ID","taskDetail.topicMenu.copyOperationId": "Copy Operation ID",+ "taskDetail.topicMenu.delete": "Delete Run",+ "taskDetail.topicMenu.deleteConfirm.content": "This run and its messages will be permanently deleted. This action cannot be undone.",+ "taskDetail.topicMenu.deleteConfirm.title": "Delete Run?","taskDetail.topicMenu.open": "Open Run","taskDetail.topicMenu.openAgentTopic": "Go to Agent conversation","taskDetail.topicMenu.stop": "Stop Run",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex d19a11eb338..67b09a3de78 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -1454,6 +1454,9 @@"taskDetail.topicDrawer.untitled": "未命名","taskDetail.topicMenu.copyId": "复制话题 ID","taskDetail.topicMenu.copyOperationId": "复制 Operation ID",+ "taskDetail.topicMenu.delete": "删除运行",+ "taskDetail.topicMenu.deleteConfirm.content": "该运行及其消息将被永久删除,此操作无法撤销。",+ "taskDetail.topicMenu.deleteConfirm.title": "删除运行?","taskDetail.topicMenu.open": "打开运行","taskDetail.topicMenu.openAgentTopic": "前往 Agent 对话","taskDetail.topicMenu.stop": "停止运行",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 61d62a36366..d866b0b6cf6 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -1569,6 +1569,10 @@ export default {'taskDetail.topicDrawer.untitled': 'Untitled','taskDetail.topicMenu.copyId': 'Copy Topic ID','taskDetail.topicMenu.copyOperationId': 'Copy Operation ID',+ 'taskDetail.topicMenu.delete': 'Delete Run',+ 'taskDetail.topicMenu.deleteConfirm.content':+ 'This run and its messages will be permanently deleted. This action cannot be undone.',+ 'taskDetail.topicMenu.deleteConfirm.title': 'Delete Run?','taskDetail.topicMenu.openAgentTopic': 'Go to Agent conversation','taskDetail.topicMenu.open': 'Open Run','taskDetail.topicMenu.stop': 'Stop Run',diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsxindex 86175e0bac4..1fdc88d7903 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsx@@ -11,7 +11,7 @@ import {Tag,Text,} from '@lobehub/ui';-import { confirmModal } from '@lobehub/ui/base-ui';+import { confirmModal, toast } from '@lobehub/ui/base-ui';import { cssVar } from 'antd-style';import {ChevronDown,@@ -22,6 +22,7 @@ import {ExternalLink,MessageCircle,MoreHorizontal,+ Trash,} from 'lucide-react';import type { KeyboardEvent } from 'react';import { memo, useCallback, useEffect, useState } from 'react';@@ -34,6 +35,7 @@ import { useActivityTime } from '@/hooks/useActivityTime';import { usePermission } from '@/hooks/usePermission';import { useTaskStore } from '@/store/task';import { taskDetailSelectors } from '@/store/task/selectors';+import { isForbiddenError } from '@/utils/forbiddenError';import { styles } from '../shared/style';import RunReplyEditor from './RunReplyEditor';@@ -87,6 +89,7 @@ const TopicCard = memo<TopicCardProps>(({ activity, defaultExpanded = true }) =>const [bodyExpanded, setBodyExpanded] = useState(defaultExpanded);const openTopicDrawer = useTaskStore((s) => s.openTopicDrawer);const cancelTopic = useTaskStore((s) => s.cancelTopic);+ const deleteTopic = useTaskStore((s) => s.deleteTopic);const addComment = useTaskStore((s) => s.addComment);const activeTaskId = useTaskStore(taskDetailSelectors.activeTaskId);const { allowed: canEditTask } = usePermission('create_content');@@ -166,6 +169,36 @@ const TopicCard = memo<TopicCardProps>(({ activity, defaultExpanded = true }) =>});}, [activity.id, cancelTopic, t]);+ // The server gates `task.deleteTopic` behind the same edit permission as+ // every other task mutation — a workspace viewer's confirm would only ever+ // come back FORBIDDEN. Route that through the shared toast instead of+ // letting the mutation reject silently into the confirm modal.+ const handleDelete = useCallback(() => {+ if (!canEditTask || !activity.id) return;+ const topicId = activity.id;+ confirmModal({+ cancelText: t('cancel', { ns: 'common' }),+ content: t('taskDetail.topicMenu.deleteConfirm.content', {+ defaultValue:+ 'This run and its messages will be permanently deleted. This action cannot be undone.',+ }),+ okButtonProps: { danger: true },+ okText: t('taskDetail.topicMenu.delete', { defaultValue: 'Delete Run' }),+ onOk: async () => {+ try {+ await deleteTopic(topicId);+ } catch (error) {+ toast.error(+ isForbiddenError(error)+ ? t('manageOnlyCreator', { ns: 'common' })+ : t('operationFailed', { ns: 'common' }),+ );+ }+ },+ title: t('taskDetail.topicMenu.deleteConfirm.title', { defaultValue: 'Delete Run?' }),+ });+ }, [activity.id, canEditTask, deleteTopic, t]);+const { text: startedAt, title: startedAtTitle } = useActivityTime(activity.time);const durationText = isRunning? formatDuration(elapsed)@@ -206,6 +239,20 @@ const TopicCard = memo<TopicCardProps>(({ activity, defaultExpanded = true }) =>label: t('taskDetail.topicMenu.copyOperationId', { defaultValue: 'Copy Operation ID' }),onClick: handleCopyOperationId,},+ { type: 'divider' as const },+ {+ danger: true,+ // A running topic is deleted server-side via interrupt-then-remove, but+ // the row already offers an explicit Stop for that case — keep delete+ // scoped to finished runs so this menu doesn't offer two destructive+ // exits for the same in-flight state. Also gated on edit permission,+ // matching the server's `task.deleteTopic` authorization.+ disabled: !activity.id || isRunning || !canEditTask,+ icon: Trash,+ key: 'delete',+ label: t('taskDetail.topicMenu.delete', { defaultValue: 'Delete Run' }),+ onClick: handleDelete,+ },];const isAgent = activity.author?.type === 'agent';diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsxindex 432eed444a6..81176b7086c 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx@@ -4,9 +4,9 @@ import { AGENT_CHAT_TOPIC_URL } from '@lobechat/const';import type { ConversationContext } from '@lobechat/types';import type { DropdownItem } from '@lobehub/ui';import { ActionIcon, copyToClipboard, DropdownMenu, Flexbox, Freeze, Tag, Text } from '@lobehub/ui';-import { FloatingPanel } from '@lobehub/ui/base-ui';+import { confirmModal, FloatingPanel, toast } from '@lobehub/ui/base-ui';import { cssVar } from 'antd-style';-import { Copy, ExternalLink, Maximize2, Minimize2, MoreHorizontal, Share2 } from 'lucide-react';+import { Copy, ExternalLink, Maximize2, Minimize2, MoreHorizontal, Share2, Trash } from 'lucide-react';import { memo, useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -29,6 +29,7 @@ import { useTaskStore } from '@/store/task';import { taskActivitySelectors, taskDetailSelectors } from '@/store/task/selectors';import { useUserStore } from '@/store/user';import { authSelectors } from '@/store/user/selectors';+import { isForbiddenError } from '@/utils/forbiddenError';import AssigneeAvatar from '../../features/AssigneeAvatar';import FeedbackInput from './FeedbackInput';@@ -128,9 +129,11 @@ const TopicChatDrawer = memo(() => {const drawerTitle = useTaskStore(taskDetailSelectors.topicDrawerTitle);const activity = useTaskStore(taskActivitySelectors.activeDrawerTopicActivity);const closeTopicDrawer = useTaskStore((s) => s.closeTopicDrawer);+ const deleteTopic = useTaskStore((s) => s.deleteTopic);const useFetchTaskDetail = useTaskStore((s) => s.useFetchTaskDetail);const enableTopicLinkShare = useServerConfigStore(serverConfigSelectors.enableBusinessFeatures);const { allowed: canShare, reason } = usePermission('edit_own_content');+ const { allowed: canEditTask } = usePermission('create_content');// Hydrate task detail when the drawer is opened outside of TaskDetailPage// (e.g. from a brief on home) so the header has agentId / status / seq.@@ -158,6 +161,37 @@ const TopicChatDrawer = memo(() => {navigate(AGENT_CHAT_TOPIC_URL(agentId, topicId));}, [agentId, closeTopicDrawer, navigate, topicId]);+ // The drawer stays open until `deleteTopic` actually succeeds: closing+ // first would drop the user back onto whatever was behind the panel with+ // no feedback if the mutation then fails (permission, network, or a topic+ // that's already gone). Only a confirmed delete tears the panel down.+ const handleDelete = useCallback(() => {+ if (!topicId) return;+ const targetTopicId = topicId;+ confirmModal({+ cancelText: t('cancel', { ns: 'common' }),+ content: t('taskDetail.topicMenu.deleteConfirm.content', {+ defaultValue:+ 'This run and its messages will be permanently deleted. This action cannot be undone.',+ }),+ okButtonProps: { danger: true },+ okText: t('taskDetail.topicMenu.delete', { defaultValue: 'Delete Run' }),+ onOk: async () => {+ try {+ await deleteTopic(targetTopicId);+ closeTopicDrawer();+ } catch (error) {+ toast.error(+ isForbiddenError(error)+ ? t('manageOnlyCreator', { ns: 'common' })+ : t('operationFailed', { ns: 'common' }),+ );+ }+ },+ title: t('taskDetail.topicMenu.deleteConfirm.title', { defaultValue: 'Delete Run?' }),+ });+ }, [closeTopicDrawer, deleteTopic, t, topicId]);+const menuItems = useMemo<DropdownItem[]>(() => [{@@ -182,12 +216,31 @@ const TopicChatDrawer = memo(() => {label: t('taskDetail.topicMenu.copyOperationId', { defaultValue: 'Copy Operation ID' }),onClick: handleCopyOperationId,},+ { type: 'divider' },+ {+ danger: true,+ // Mirrors the run row's menu: a running topic already has an explicit+ // Stop affordance, so delete here stays scoped to finished runs, and+ // is also gated on edit permission like the server's `task.deleteTopic`.+ // `activity` can be briefly (or, for a topic without a parent task,+ // permanently) unresolved while the task detail hydrates — an unknown+ // status is treated as ineligible (same as running) rather than+ // defaulting to enabled.+ disabled: !topicId || !canEditTask || !activity?.status || activity.status === 'running',+ icon: Trash,+ key: 'delete',+ label: t('taskDetail.topicMenu.delete', { defaultValue: 'Delete Run' }),+ onClick: handleDelete,+ },],[activity?.operationId,+ activity?.status,agentId,+ canEditTask,handleCopyOperationId,handleCopyTopicId,+ handleDelete,handleOpenAgentTopic,t,topicId,