fix: persist composer mode during send
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-03-19 00:30:41 +08:00
parent 1a6a1a8d6e
commit a4abda497c

View File

@ -2999,6 +2999,7 @@ export function CanvasChatPanel({
return [] as string[];
}, [isVideoModel, videoParams]);
const activeComposerMode = composerModeOverride || computedComposerMode;
const activeComposerModeRef = useRef(activeComposerMode);
const agentUploadSlots = useMemo(() => {
if (
activeComposerMode !== "agent" ||
@ -3240,6 +3241,10 @@ export function CanvasChatPanel({
);
// 默认选择模型(根据系统设置)
useEffect(() => {
activeComposerModeRef.current = activeComposerMode;
}, [activeComposerMode]);
useEffect(() => {
if (!selectedModelId && siteSettings) {
currentModelIdRef.current = "auto";
@ -3456,6 +3461,7 @@ export function CanvasChatPanel({
(mode: "agent" | "image" | "video" | "detail") => {
hiddenPromptRef.current = null;
autoContextRef.current = null;
activeComposerModeRef.current = mode;
setComposerModeOverride(mode);
if (mode === "agent") {
@ -3891,10 +3897,12 @@ export function CanvasChatPanel({
console.log("[CanvasChat] Preparing request:", {
id: rawId,
modelId: currentModelIdRef.current,
composerMode: activeComposerModeRef.current,
imageParams: imageParamsRef.current,
contextPayload: buildContextPayload(),
lastMessage: request.messages.at(-1),
});
const effectiveComposerMode = activeComposerModeRef.current || activeComposerMode;
const hiddenPrompt = hiddenPromptRef.current || undefined;
const autoContext = autoContextRef.current || undefined;
const contextPayload = buildContextPayload();
@ -3915,11 +3923,11 @@ export function CanvasChatPanel({
id: rawId,
message: request.messages.at(-1),
agentPresetId:
activeComposerMode === "agent" && selectedAgentPreset?.id
effectiveComposerMode === "agent" && selectedAgentPreset?.id
? selectedAgentPreset.id
: undefined,
selectedChatModel: currentModelIdRef.current,
composerMode: activeComposerMode,
composerMode: effectiveComposerMode,
selectedVisibilityType: "private",
deepThinkingEnabled: requestIsConversationModel
? false
@ -4936,7 +4944,8 @@ export function CanvasChatPanel({
if (imageNodes.length === 0) return undefined;
const shouldIsolateDirectModeContext = activeComposerMode !== "agent";
const effectiveComposerMode = activeComposerModeRef.current || activeComposerMode;
const shouldIsolateDirectModeContext = effectiveComposerMode !== "agent";
if (shouldIsolateDirectModeContext && selectedImageNodes.length === 0) {
return undefined;
}
@ -7084,6 +7093,8 @@ export function CanvasChatPanel({
if (!textContent && hasWorkflowContext && workflowContext?.summaryText) {
textContent = `请基于当前工作流设定生成方案:${workflowContext.summaryText}`;
}
const effectiveComposerMode = activeComposerModeRef.current || activeComposerMode;
if (!textContent && hasAgentUploadSlots && selectedAgentPreset) {
textContent = `请按「${selectedAgentPreset.name}」智能体配置顺序处理产品图1、产品图2和模特图。`;
}
@ -7104,7 +7115,7 @@ export function CanvasChatPanel({
);
}
if (
activeComposerMode === "agent" &&
effectiveComposerMode === "agent" &&
selectedAgentPreset?.type === "text" &&
selectedAgentPreset.slots?.length
) {
@ -7166,7 +7177,7 @@ export function CanvasChatPanel({
text: textContent,
attachments: normalizedAttachmentKeys,
skillTagId: selectedSkillTag?.id || null,
mode: activeComposerMode,
mode: effectiveComposerMode,
});
if (shouldBlockDuplicateSend(activeChatId, sendSignature)) {