Skip to content

🤯 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.

✨ feat(home): create Task-mode entries without starting them (#20305)

Arvin Xue5ab0aea72fe
diff --git a/locales/en-US/home.json b/locales/en-US/home.json
index 6ac65b95733..f7295794a73 100644
--- a/locales/en-US/home.json
+++ b/locales/en-US/home.json
@@ -93,13 +93,15 @@
"dashboard.greeting.subtitle": "What would you like to work on?",
"dashboard.mode.chat": "Agent",
"dashboard.mode.task": "Task",
- "dashboard.modeDesc.task": "Create a task, start it now, and track its progress",
+ "dashboard.modeDesc.task": "Create a task and start it when you are ready",
"dashboard.placeholder.chat": "Ask, create, or start a task",
- "dashboard.placeholder.task": "Describe a task to start right away",
+ "dashboard.placeholder.task": "Describe a task to create",
"dashboard.rail.hide": "Hide activity",
"dashboard.rail.show": "Show activity",
"dashboard.scheduledTask.title": "Scheduled tasks",
"dashboard.submitFailed": "Could not submit. Your draft has been kept.",
+ "dashboard.task.created": "Task created",
+ "dashboard.task.createdHint": "Find it in Recent tasks.",
"dashboard.task.empty": "No tasks yet",
"dashboard.task.title": "Recent tasks",
"dashboard.task.unsupportedContext": "Task mode does not support attachments or selected context yet. Remove them or switch to Agent mode; your draft has been kept.",
diff --git a/locales/zh-CN/home.json b/locales/zh-CN/home.json
index 2df528aea06..13bd8049304 100644
--- a/locales/zh-CN/home.json
+++ b/locales/zh-CN/home.json
@@ -93,13 +93,15 @@
"dashboard.greeting.subtitle": "你想处理什么?",
"dashboard.mode.chat": "Agent",
"dashboard.mode.task": "任务",
- "dashboard.modeDesc.task": "创建任务并立即执行,持续跟踪进度",
+ "dashboard.modeDesc.task": "创建任务,准备好后再开始执行",
"dashboard.placeholder.chat": "提问、创建内容或启动任务",
- "dashboard.placeholder.task": "描述要立即开始的任务",
+ "dashboard.placeholder.task": "描述要创建的任务",
"dashboard.rail.hide": "隐藏动态",
"dashboard.rail.show": "显示动态",
"dashboard.scheduledTask.title": "定时任务",
"dashboard.submitFailed": "提交失败,草稿已保留。",
+ "dashboard.task.created": "任务已创建",
+ "dashboard.task.createdHint": "可在「最近任务」中查看。",
"dashboard.task.empty": "暂无任务",
"dashboard.task.title": "最近任务",
"dashboard.task.unsupportedContext": "任务模式暂不支持附件或已选上下文。请移除它们或切换到 Agent 模式;草稿已保留。",
diff --git a/packages/locales/src/default/home.ts b/packages/locales/src/default/home.ts
index 5c83f66efbf..53df5c97e90 100644
--- a/packages/locales/src/default/home.ts
+++ b/packages/locales/src/default/home.ts
@@ -99,13 +99,15 @@ export default {
'dashboard.greeting.subtitle': 'What would you like to work on?',
'dashboard.mode.chat': 'Agent',
'dashboard.mode.task': 'Task',
- 'dashboard.modeDesc.task': 'Create a task, start it now, and track its progress',
+ 'dashboard.modeDesc.task': 'Create a task and start it when you are ready',
'dashboard.placeholder.chat': 'Ask, create, or start a task',
- 'dashboard.placeholder.task': 'Describe a task to start right away',
+ 'dashboard.placeholder.task': 'Describe a task to create',
'dashboard.rail.hide': 'Hide activity',
'dashboard.rail.show': 'Show activity',
'dashboard.scheduledTask.title': 'Scheduled tasks',
'dashboard.submitFailed': 'Could not submit. Your draft has been kept.',
+ 'dashboard.task.created': 'Task created',
+ 'dashboard.task.createdHint': 'Find it in Recent tasks.',
'dashboard.task.empty': 'No tasks yet',
'dashboard.task.title': 'Recent tasks',
'dashboard.task.viewAll': 'View all',
diff --git a/src/features/Home/InputArea/useSend.test.ts b/src/features/Home/InputArea/useSend.test.ts
index c83fdf19243..8b0164e254f 100644
--- a/src/features/Home/InputArea/useSend.test.ts
+++ b/src/features/Home/InputArea/useSend.test.ts
@@ -4,6 +4,7 @@
import { act, renderHook } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';
import type { SendButtonHandler } from '@/features/ChatInput/store/initialState';
import { useSend } from './useSend';
@@ -22,6 +23,7 @@ const createTaskMock = vi.hoisted(() => vi.fn());
const runTaskMock = vi.hoisted(() => vi.fn());
const toggleTaskAgentPanelMock = vi.hoisted(() => vi.fn());
const messageErrorMock = vi.hoisted(() => vi.fn());
+const messageSuccessMock = vi.hoisted(() => vi.fn());
const chatState = vi.hoisted(() => ({
inputMessage: 'hello',
@@ -94,7 +96,7 @@ const activeWorkspaceIdMock = vi.hoisted(() => ({
vi.mock('@lobehub/ui/base-ui', async (importOriginal) => ({
...(await importOriginal<object>()),
- toast: { error: messageErrorMock },
+ toast: { error: messageErrorMock, success: messageSuccessMock },
}));
vi.mock('@/hooks/usePermission', () => ({
@@ -187,6 +189,7 @@ describe('Home InputArea useSend', () => {
runTaskMock.mockReset();
toggleTaskAgentPanelMock.mockReset();
messageErrorMock.mockReset();
+ messageSuccessMock.mockReset();
homeDailyBriefState.advance.mockReset();
homeDailyBriefState.currentPair = undefined;
chatState.inputMessage = 'hello';
@@ -200,7 +203,7 @@ describe('Home InputArea useSend', () => {
activeWorkspaceIdMock.value = null;
});
- it('creates and starts a private workspace task with the selected Agent', async () => {
+ it('creates a private workspace task without starting it', async () => {
activeWorkspaceIdMock.value = 'workspace-1';
globalState.systemStatus.homeSelectedAgentId = 'agt_custom';
homeState.ungroupedAgents = [{ id: 'agt_custom', type: 'agent' }];
@@ -209,7 +212,6 @@ describe('Home InputArea useSend', () => {
assigneeAgentId: 'agt_custom',
identifier: 'T-26',
});
- runTaskMock.mockResolvedValue({ topicId: 'tpc-26' });
const { result } = renderHook(() => useSend('task'));
const params: Parameters<SendButtonHandler>[0] = {
clearContent: vi.fn(),
@@ -229,10 +231,26 @@ describe('Home InputArea useSend', () => {
name: 'Prepare the weekly report',
visibility: 'private',
});
- expect(runTaskMock).toHaveBeenCalledWith('T-26', undefined, { throwOnError: true });
+ // Task mode records the task; it must not launch a run, open the task
+ // panel, or navigate away from Home.
+ expect(runTaskMock).not.toHaveBeenCalled();
+ expect(toggleTaskAgentPanelMock).not.toHaveBeenCalled();
+ expect(routerMock.push).not.toHaveBeenCalled();
expect(sendMessageMock).not.toHaveBeenCalled();
- expect(toggleTaskAgentPanelMock).toHaveBeenCalledWith(true);
- expect(routerMock.push).toHaveBeenCalledWith('/tasks?agentId=agt_custom&topicId=tpc-26');
+ expect(messageSuccessMock).toHaveBeenCalledWith(
+ expect.objectContaining({ title: 'dashboard.task.created' }),
+ );
+ // The toast is the only handle on the task once the composer is cleared, so
+ // its action must open that task rather than just dismiss the toast.
+ const [{ actions }] = messageSuccessMock.mock.calls.at(-1) as [
+ { actions: { label: string; onClick: () => void }[] },
+ ];
+ expect(actions).toHaveLength(1);
+ expect(actions[0].label).toBe('taskIntent.openCreated');
+ actions[0].onClick();
+ expect(routerMock.push).toHaveBeenCalledWith(
+ taskDetailPath('T-26', 'agt_custom', 'Prepare the weekly report'),
+ );
expect(clearContentMock).toHaveBeenCalledTimes(1);
});
@@ -258,9 +276,8 @@ describe('Home InputArea useSend', () => {
expect(messageErrorMock).toHaveBeenCalledWith('dashboard.submitFailed');
});
- it('keeps the draft and stays on Home when task execution fails', async () => {
- createTaskMock.mockResolvedValue({ assigneeAgentId: 'agt_inbox', identifier: 'T-27' });
- runTaskMock.mockRejectedValue(new Error('run failed'));
+ it('keeps the draft and stays on Home when task creation throws', async () => {
+ createTaskMock.mockRejectedValue(new Error('create failed'));
const { result } = renderHook(() => useSend('task'));
const params: Parameters<SendButtonHandler>[0] = {
clearContent: vi.fn(),
@@ -273,36 +290,13 @@ describe('Home InputArea useSend', () => {
await result.current.send(params);
});
+ expect(runTaskMock).not.toHaveBeenCalled();
expect(routerMock.push).not.toHaveBeenCalled();
expect(clearContentMock).not.toHaveBeenCalled();
+ expect(messageSuccessMock).not.toHaveBeenCalled();
expect(messageErrorMock).toHaveBeenCalledWith('dashboard.submitFailed');
});
- it('reuses the created task when retrying after its first run fails', async () => {
- createTaskMock.mockResolvedValue({ assigneeAgentId: 'agt_inbox', identifier: 'T-28' });
- runTaskMock
- .mockRejectedValueOnce(new Error('run failed'))
- .mockResolvedValueOnce({ topicId: 'tpc-28' });
- const { result } = renderHook(() => useSend('task'));
- const params: Parameters<SendButtonHandler>[0] = {
- clearContent: vi.fn(),
- editor: {} as Parameters<SendButtonHandler>[0]['editor'],
- getEditorData: () => ({ type: 'doc' }),
- getMarkdownContent: () => 'Prepare the weekly report',
- };
-
- await act(async () => {
- await result.current.send(params);
- await result.current.send(params);
- });
-
- expect(createTaskMock).toHaveBeenCalledTimes(1);
- expect(runTaskMock).toHaveBeenCalledTimes(2);
- expect(runTaskMock).toHaveBeenNthCalledWith(2, 'T-28', undefined, { throwOnError: true });
- expect(toggleTaskAgentPanelMock).toHaveBeenCalledWith(true);
- expect(routerMock.push).toHaveBeenCalledWith('/tasks?agentId=agt_inbox&topicId=tpc-28');
- });
-
it('does not discard attachments that Task mode cannot persist', async () => {
fileState.chatUploadFileList = [{ id: 'file-1' }] as any;
const { result } = renderHook(() => useSend('task'));
diff --git a/src/features/Home/InputArea/useSend.ts b/src/features/Home/InputArea/useSend.ts
index 9ee18c3ecac..8b0eb40d60f 100644
--- a/src/features/Home/InputArea/useSend.ts
+++ b/src/features/Home/InputArea/useSend.ts
@@ -1,11 +1,11 @@
import { AGENT_CHAT_TOPIC_URL, AGENT_CHAT_URL } from '@lobechat/const';
import { toast } from '@lobehub/ui/base-ui';
-import { useCallback, useRef, useState } from 'react';
+import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
-import { buildTaskHandoffPath } from '@/features/AgentTaskManager/taskHandoff';
+import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';
import type { SendButtonHandler } from '@/features/ChatInput/store/initialState';
import { buildMessageContextSelections } from '@/features/ChatInput/utils/contextSelections';
import { useResourceAccess } from '@/features/ResourcePermission/useResourceAccess';
@@ -17,7 +17,6 @@ import { useAgentStore } from '@/store/agent';
import { builtinAgentSelectors } from '@/store/agent/selectors';
import { useChatStore } from '@/store/chat';
import { fileChatSelectors, useFileStore } from '@/store/file';
-import { useGlobalStore } from '@/store/global';
import { useHomeStore } from '@/store/home';
import { useTaskStore } from '@/store/task';
@@ -47,15 +46,9 @@ const ensureAgentConfigLoaded = async (agentId: string): Promise<void> => {
if (config) agentState.internal_dispatchAgentMap(agentId, config);
};
-interface PendingTaskRun {
- agentId: string;
- identifier: string;
- instruction: string;
- workspaceId: string | null;
-}
-
export const useSend = (mode: HomeMode = 'chat') => {
const { t } = useTranslation('home');
+ const { t: tChat } = useTranslation('chat');
const router = useQueryRoute();
const activeWorkspaceId = useActiveWorkspaceId();
const activeWorkspaceSlug = useActiveWorkspaceSlug();
@@ -66,10 +59,7 @@ export const useSend = (mode: HomeMode = 'chat') => {
const homeInputLoading = useHomeStore((s) => s.homeInputLoading);
const createTask = useTaskStore((s) => s.createTask);
- const runTask = useTaskStore((s) => s.runTask);
- const toggleTaskAgentPanel = useGlobalStore((s) => s.toggleTaskAgentPanel);
const [isSubmitting, setIsSubmitting] = useState(false);
- const pendingTaskRunRef = useRef<PendingTaskRun | null>(null);
const inboxAgentId = useAgentStore(builtinAgentSelectors.inboxAgentId);
const { agentId: selectedAgentId } = useResolvedHomeAgentId();
@@ -142,44 +132,45 @@ export const useSend = (mode: HomeMode = 'chat') => {
try {
const { contextSelections, pageSelections } = buildMessageContextSelections(contextList);
- // Task mode is a commitment, not a proposal: the row is written and the
- // run is launched here. Routing it through the agent would leave both
- // outcomes to a model that is told elsewhere not to start work on its
- // own — pressing send in this mode IS the instruction to start.
+ // Task mode records a task; it does not start one. Pressing send here
+ // writes the row and keeps the user on the Home composer, where the new
+ // task shows up under Recent tasks. Starting the run stays an explicit
+ // action on the task itself, so a quick jot cannot launch an agent the
+ // user only meant to note down.
if (mode === 'task') {
if (!message || !selectedAgentId) return;
setIsSubmitting(true);
- const pendingTaskRun = pendingTaskRunRef.current;
- const canRetryPendingTask =
- pendingTaskRun?.agentId === selectedAgentId &&
- pendingTaskRun.instruction === message &&
- pendingTaskRun.workspaceId === (activeWorkspaceId ?? null);
-
- let taskRun = canRetryPendingTask ? pendingTaskRun : null;
- if (!taskRun) {
- const created = await createTask({
- assigneeAgentId: selectedAgentId,
- editorData,
- instruction: message,
- name: taskNameFromMessage(message),
- visibility: activeWorkspaceId ? 'private' : undefined,
- });
- if (!created?.identifier) throw new Error('Task creation returned no identifier');
- taskRun = {
- agentId: created.assigneeAgentId ?? selectedAgentId,
- identifier: created.identifier,
- instruction: message,
- workspaceId: activeWorkspaceId ?? null,
- };
- pendingTaskRunRef.current = taskRun;
- }
-
- const result = await runTask(taskRun.identifier, undefined, { throwOnError: true });
- if (!result?.topicId) throw new Error('Task run did not return a topic');
- pendingTaskRunRef.current = null;
+ const name = taskNameFromMessage(message);
+ const created = await createTask({
+ assigneeAgentId: selectedAgentId,
+ editorData,
+ instruction: message,
+ name,
+ visibility: activeWorkspaceId ? 'private' : undefined,
+ });
+ if (!created?.identifier) throw new Error('Task creation returned no identifier');
submitted = true;
- toggleTaskAgentPanel(true);
- router.push(buildTaskHandoffPath(taskRun.agentId, result.topicId));
+ // The task outlives the toast, so the toast is the only handle on the
+ // thing the user just wrote. Say where it went and give it a way in,
+ // mirroring the task list's own create toast.
+ toast.success({
+ actions: [
+ {
+ label: tChat('taskIntent.openCreated'),
+ onClick: () =>
+ router.push(
+ taskDetailPath(
+ created.identifier,
+ created.assigneeAgentId ?? selectedAgentId,
+ name,
+ ),
+ ),
+ variant: 'text',
+ },
+ ],
+ description: t('dashboard.task.createdHint'),
+ title: t('dashboard.task.created'),
+ });
return;
}
@@ -281,13 +272,12 @@ export const useSend = (mode: HomeMode = 'chat') => {
currentPair,
mode,
createTask,
- runTask,
- toggleTaskAgentPanel,
inboxAgentId,
selectedAgentId,
canUseResource,
canCreateContent,
t,
+ tChat,
],
);