fix(agent): 输入草稿按会话保留,切换会话、关抽屉不丢

会话面板与新对话输入框的草稿原来是组件内状态,切到别的会话或 Esc 关抽屉就没了。
改为按会话(以及列表页 / 抽屉两处新对话)分键记在模块里,发送成功后清掉。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-06 18:02:50 +08:00
1 parent 164a27fd80
commit 9f499ac7c2
5 files changed
+86 -6

No files matched your search

@@ -40,6 +40,7 @@ import {
runPlanIds,
} from "./agent-conversation.tsx";
import { RunPlan } from "./agent-interaction.tsx";
import { readDraft, runDraftKey, writeDraft } from "./agent-nav.ts";
import { shortGoalTitle } from "./agent-store.ts";
import { SubagentTree } from "./agent-subagent-tree.tsx";
import { callCounts, sessionStatsParts, stepProgress } from "./conversation-model.ts";
@@ -71,6 +72,7 @@ export function GoalComposer({
onClearContext,
defaultGoal = "",
suggestions,
draftKey,
}: {
onSubmit: (goal: string, opts: AgentSessionOptions) => void;
pending: boolean;
@@ -80,8 +82,14 @@ export function GoalComposer({
defaultGoal?: string;
/** 快捷目标:输入框为空时显示 */
suggestions?: string[];
/** 草稿记在这个键下(没有预填目标时恢复);发送成功后由调用方清掉 */
draftKey?: string;
}) {
const [goal, setGoal] = useState(defaultGoal);
const [goal, setGoalState] = useState(() => defaultGoal || readDraft(draftKey));
const setGoal = (text: string) => {
setGoalState(text);
writeDraft(draftKey, text);
};
const box = useRef<HTMLDivElement>(null);
const fill = (text: string) => {
setGoal(text);
@@ -295,7 +303,12 @@ export function AgentRunPanel({
const append = useAppendAgentMessage();
const create = useCreateAgentRun();
const navigate = useNavigate();
const [msg, setMsg] = useState("");
// 草稿按会话记:切到别的会话再回来还在,不会串到别的会话
const [msg, setMsgState] = useState(() => readDraft(runDraftKey(runId)));
const setMsg = (text: string) => {
setMsgState(text);
writeDraft(runDraftKey(runId), text);
};
const [confirmStop, setConfirmStop] = useState(false);
const sseStatus = useSseStatus();
const qc = useQueryClient();