fix: isolate direct image mode context
This commit is contained in:
parent
0fa2c8b40e
commit
1a6a1a8d6e
@ -3141,6 +3141,7 @@ export async function POST(request: Request) {
|
|||||||
const deepThinkingOn = deepThinkingEnabled !== false;
|
const deepThinkingOn = deepThinkingEnabled !== false;
|
||||||
const shouldRespectDirectComposerMode =
|
const shouldRespectDirectComposerMode =
|
||||||
composerMode === "image" || composerMode === "video" || composerMode === "detail";
|
composerMode === "image" || composerMode === "video" || composerMode === "detail";
|
||||||
|
const shouldIsolateDirectComposerContext = shouldRespectDirectComposerMode;
|
||||||
let shouldRunAgentConversation = finalModelId === "auto";
|
let shouldRunAgentConversation = finalModelId === "auto";
|
||||||
let shouldKeepSelectedModel = false;
|
let shouldKeepSelectedModel = false;
|
||||||
if (shouldRespectDirectComposerMode && shouldRunAgentConversation) {
|
if (shouldRespectDirectComposerMode && shouldRunAgentConversation) {
|
||||||
@ -3338,25 +3339,29 @@ export async function POST(request: Request) {
|
|||||||
allowWorkflowExecution?: boolean;
|
allowWorkflowExecution?: boolean;
|
||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
const activeStoryboardTaskForChat = await getLatestActiveVideoStoryboardTaskByChatId({
|
const activeStoryboardTaskForChat = shouldIsolateDirectComposerContext
|
||||||
chatId: id,
|
? null
|
||||||
}).catch((storyboardLookupError) => {
|
: await getLatestActiveVideoStoryboardTaskByChatId({
|
||||||
console.warn(
|
chatId: id,
|
||||||
"[Chat API] Failed to preload active storyboard task before smart auto mode:",
|
}).catch((storyboardLookupError) => {
|
||||||
storyboardLookupError
|
console.warn(
|
||||||
);
|
"[Chat API] Failed to preload active storyboard task before smart auto mode:",
|
||||||
return null;
|
storyboardLookupError
|
||||||
});
|
);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
requestWorkingState = await getConversationWorkingStateByChatId({
|
requestWorkingState = shouldIsolateDirectComposerContext
|
||||||
chatId: id,
|
? null
|
||||||
}).catch((workingStatePreloadError) => {
|
: await getConversationWorkingStateByChatId({
|
||||||
console.warn(
|
chatId: id,
|
||||||
"[Chat API] Failed to preload conversation working state before smart auto mode:",
|
}).catch((workingStatePreloadError) => {
|
||||||
workingStatePreloadError
|
console.warn(
|
||||||
);
|
"[Chat API] Failed to preload conversation working state before smart auto mode:",
|
||||||
return null;
|
workingStatePreloadError
|
||||||
});
|
);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
const hasImageInputForConversationAction = message.parts.some((part: any) =>
|
const hasImageInputForConversationAction = message.parts.some((part: any) =>
|
||||||
part?.type === "file" || part?.type === "image" || part?.type === "image_url"
|
part?.type === "file" || part?.type === "image" || part?.type === "image_url"
|
||||||
);
|
);
|
||||||
@ -3535,7 +3540,7 @@ export async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
autoTextForFallback = smartAutoInputText;
|
autoTextForFallback = smartAutoInputText;
|
||||||
if (!requestWorkingState) {
|
if (!requestWorkingState && !shouldIsolateDirectComposerContext) {
|
||||||
requestWorkingState = await getConversationWorkingStateByChatId({
|
requestWorkingState = await getConversationWorkingStateByChatId({
|
||||||
chatId: id,
|
chatId: id,
|
||||||
});
|
});
|
||||||
@ -4775,21 +4780,25 @@ export async function POST(request: Request) {
|
|||||||
messagesFromDb = await getMessagesByChatId({ id });
|
messagesFromDb = await getMessagesByChatId({ id });
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadedMessagesForBoundary = messagesFromDb;
|
const loadedMessagesForBoundary = shouldIsolateDirectComposerContext ? [] : messagesFromDb;
|
||||||
messagesFromDb = pruneTaskBoundaryHistoryMessages({
|
messagesFromDb = shouldIsolateDirectComposerContext
|
||||||
decision: taskBoundaryDecision,
|
? []
|
||||||
messages: loadedMessagesForBoundary,
|
: pruneTaskBoundaryHistoryMessages({
|
||||||
purpose: "model",
|
decision: taskBoundaryDecision,
|
||||||
hasCurrentImageInput: hasImageInputForConversationAction,
|
messages: loadedMessagesForBoundary,
|
||||||
});
|
purpose: "model",
|
||||||
messagesForMediaInput = pruneTaskBoundaryHistoryMessages({
|
hasCurrentImageInput: hasImageInputForConversationAction,
|
||||||
decision: taskBoundaryDecision,
|
});
|
||||||
messages: loadedMessagesForBoundary,
|
messagesForMediaInput = shouldIsolateDirectComposerContext
|
||||||
purpose: "media",
|
? []
|
||||||
hasCurrentImageInput: hasImageInputForConversationAction,
|
: pruneTaskBoundaryHistoryMessages({
|
||||||
});
|
decision: taskBoundaryDecision,
|
||||||
|
messages: loadedMessagesForBoundary,
|
||||||
|
purpose: "media",
|
||||||
|
hasCurrentImageInput: hasImageInputForConversationAction,
|
||||||
|
});
|
||||||
|
|
||||||
if (!requestWorkingState) {
|
if (!requestWorkingState && !shouldIsolateDirectComposerContext) {
|
||||||
requestWorkingState = await getConversationWorkingStateByChatId({
|
requestWorkingState = await getConversationWorkingStateByChatId({
|
||||||
chatId: id,
|
chatId: id,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4936,10 +4936,17 @@ export function CanvasChatPanel({
|
|||||||
|
|
||||||
if (imageNodes.length === 0) return undefined;
|
if (imageNodes.length === 0) return undefined;
|
||||||
|
|
||||||
|
const shouldIsolateDirectModeContext = activeComposerMode !== "agent";
|
||||||
|
if (shouldIsolateDirectModeContext && selectedImageNodes.length === 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const MAX_CONTEXT_IMAGES = 12;
|
const MAX_CONTEXT_IMAGES = 12;
|
||||||
const selectedIds = new Set(selectedImageNodes.map((node) => node.id));
|
const selectedIds = new Set(selectedImageNodes.map((node) => node.id));
|
||||||
const prioritizedNodes =
|
const prioritizedNodes =
|
||||||
selectedImageNodes.length > 0
|
shouldIsolateDirectModeContext
|
||||||
|
? selectedImageNodes
|
||||||
|
: selectedImageNodes.length > 0
|
||||||
? [
|
? [
|
||||||
...selectedImageNodes,
|
...selectedImageNodes,
|
||||||
...imageNodes.filter((node) => !selectedIds.has(node.id)),
|
...imageNodes.filter((node) => !selectedIds.has(node.id)),
|
||||||
@ -4985,7 +4992,7 @@ export function CanvasChatPanel({
|
|||||||
isSelected: selectedIds.has(node.id),
|
isSelected: selectedIds.has(node.id),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}, [canvasId, nodes, selectedImageNodes]);
|
}, [activeComposerMode, canvasId, nodes, selectedImageNodes]);
|
||||||
|
|
||||||
const updateAttachmentAtVideoSlot = useCallback(
|
const updateAttachmentAtVideoSlot = useCallback(
|
||||||
(slotIndex: number, attachment: PickedObjectAttachment | null) => {
|
(slotIndex: number, attachment: PickedObjectAttachment | null) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user