fix: preserve live agent mode payload in workspace sends
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-23 20:28:41 +08:00
parent 1eb05c980d
commit 53f8cd7052
5 changed files with 154 additions and 28 deletions

View File

@ -358,6 +358,13 @@ export function AgentDetailReferenceStitchDialog({
setCutLines(snapshot.defaultCutLines);
}, [snapshot]);
const handleClearCutLines = useCallback(() => {
setCutLines([]);
setDraggingLineIndex(null);
setIsAddingCutLine(false);
setPreviewCutLineY(null);
}, []);
const handleRemoveCutLine = useCallback((index: number) => {
setCutLines((current) => current.filter((_, currentIndex) => currentIndex !== index));
}, []);
@ -549,6 +556,16 @@ export function AgentDetailReferenceStitchDialog({
<RotateCcw className="mr-2 h-4 w-4" />
恢复原页边界
</Button>
<Button
type="button"
variant="outline"
onClick={handleClearCutLines}
disabled={!snapshot || isLoading || isApplying || normalizedCutLines.length === 0}
className="border-red-400/20 bg-red-500/[0.06] text-red-100 hover:bg-red-500/[0.14] hover:text-red-50"
>
<Trash2 className="mr-2 h-4 w-4" />
清空切线
</Button>
<div className="text-xs text-white/42">
默认切线已按原始详情页边界生成,可直接拖动横线微调。
{isAddingCutLine ? " 当前已进入加线模式,移动鼠标预览位置后点击长图即可落线。" : ""}

View File

@ -234,6 +234,24 @@ export function AgentGenerationWorkspace({
() => selectableModels.find((model) => model.id === selectedModelId) || selectableModels[0],
[selectableModels, selectedModelId]
);
const transportStateRef = useRef<{
selectedAgentPresetId: string | null;
selectedModelId: string;
imageParams: ImageGenerationParams;
}>({
selectedAgentPresetId: null,
selectedModelId: "auto",
imageParams: {
aspectRatio: "auto",
imageSize: "2K",
imageCount: 1,
},
});
transportStateRef.current = {
selectedAgentPresetId: selectedAgentPresetId || null,
selectedModelId,
imageParams,
};
const { messages, setMessages, sendMessage, status } = useChat<ChatMessage>({
id: chatId,
@ -244,15 +262,16 @@ export function AgentGenerationWorkspace({
api: "/api/chat",
fetch: fetchWithErrorHandlers,
prepareSendMessagesRequest(request) {
const transportState = transportStateRef.current;
return {
body: {
id: rawChatId,
message: request.messages.at(-1),
hiddenPrompt: hiddenPromptRef.current || undefined,
agentPresetId: selectedAgentPresetId || undefined,
selectedChatModel: selectedModelId,
agentPresetId: transportState.selectedAgentPresetId || undefined,
selectedChatModel: transportState.selectedModelId,
selectedVisibilityType: "private",
imageParams,
imageParams: transportState.imageParams,
},
};
},

View File

@ -152,6 +152,24 @@ export function AgentGenerationWorkspaceDark({
() => selectableModels.find((model) => model.id === selectedModelId) || selectableModels[0],
[selectableModels, selectedModelId]
);
const transportStateRef = useRef<{
selectedAgentPresetId: string | null;
selectedModelId: string;
imageParams: ImageGenerationParams;
}>({
selectedAgentPresetId: null,
selectedModelId: "auto",
imageParams: {
aspectRatio: "auto",
imageSize: "2K",
imageCount: 1,
},
});
transportStateRef.current = {
selectedAgentPresetId: selectedAgentPresetId || null,
selectedModelId,
imageParams,
};
const { messages, setMessages, sendMessage, status } = useChat<ChatMessage>({
id: chatId,
@ -162,15 +180,16 @@ export function AgentGenerationWorkspaceDark({
api: "/api/chat",
fetch: fetchWithErrorHandlers,
prepareSendMessagesRequest(request) {
const transportState = transportStateRef.current;
return {
body: {
id: rawChatId,
message: request.messages.at(-1),
hiddenPrompt: hiddenPromptRef.current || undefined,
agentPresetId: selectedAgentPresetId || undefined,
selectedChatModel: selectedModelId,
agentPresetId: transportState.selectedAgentPresetId || undefined,
selectedChatModel: transportState.selectedModelId,
selectedVisibilityType: "private",
imageParams,
imageParams: transportState.imageParams,
},
};
},

View File

@ -759,6 +759,57 @@ export function AgentGenerationWorkspaceDarkV2({
const skuReplacementCandidates = skuReplacementState.candidates;
const skuReplacementSelectedCandidateId = skuReplacementState.selectedCandidateId;
const skuReplacementReferenceCards = skuReplacementState.references;
const transportStateRef = useRef<{
selectedAgentPresetId: string | null;
selectedAgentPresetType: AgentPreset["type"] | null;
selectedModelId: string;
imageParams: ImageGenerationParams;
isDetailReplacementPreset: boolean;
isSkuReplacementPreset: boolean;
detailReplacementQueryInput: string;
detailReplacementSelectedCandidateId: string | null;
detailReplacementReferenceCards: typeof detailReplacementReferenceCards;
skuReplacementQueryInput: string;
skuReplacementQueryType: typeof skuReplacementQueryType;
skuReplacementSelectedCandidateId: string | null;
skuReplacementReferenceCards: typeof skuReplacementReferenceCards;
selectedProductAttachmentCount: number;
}>({
selectedAgentPresetId: null,
selectedAgentPresetType: null,
selectedModelId: "auto",
imageParams: {
aspectRatio: "auto",
imageSize: "2K",
imageCount: 1,
},
isDetailReplacementPreset: false,
isSkuReplacementPreset: false,
detailReplacementQueryInput: "",
detailReplacementSelectedCandidateId: null,
detailReplacementReferenceCards: [],
skuReplacementQueryInput: "",
skuReplacementQueryType: "sku",
skuReplacementSelectedCandidateId: null,
skuReplacementReferenceCards: [],
selectedProductAttachmentCount: 0,
});
transportStateRef.current = {
selectedAgentPresetId: selectedAgentPresetId || null,
selectedAgentPresetType: selectedAgentPreset?.type || null,
selectedModelId,
imageParams,
isDetailReplacementPreset,
isSkuReplacementPreset,
detailReplacementQueryInput,
detailReplacementSelectedCandidateId: detailReplacementSelectedCandidateId || null,
detailReplacementReferenceCards,
skuReplacementQueryInput,
skuReplacementQueryType,
skuReplacementSelectedCandidateId: skuReplacementSelectedCandidateId || null,
skuReplacementReferenceCards,
selectedProductAttachmentCount: selectedProductAttachments.length,
};
const selectableModels = useMemo(() => {
const imageModels = (modelsData?.models || []).filter(
@ -791,26 +842,27 @@ export function AgentGenerationWorkspaceDarkV2({
api: "/api/chat",
fetch: fetchWithErrorHandlers,
prepareSendMessagesRequest(request) {
const transportState = transportStateRef.current;
const replacementModePayload =
selectedAgentPreset?.type === "image" &&
(isDetailReplacementPreset || isSkuReplacementPreset)
transportState.selectedAgentPresetType === "image" &&
(transportState.isDetailReplacementPreset || transportState.isSkuReplacementPreset)
? {
modeType: isDetailReplacementPreset
modeType: transportState.isDetailReplacementPreset
? ("detail_replacement" as const)
: ("sku_replacement" as const),
query: isDetailReplacementPreset
? detailReplacementQueryInput.trim()
: skuReplacementQueryInput.trim(),
queryType: isDetailReplacementPreset
query: transportState.isDetailReplacementPreset
? transportState.detailReplacementQueryInput.trim()
: transportState.skuReplacementQueryInput.trim(),
queryType: transportState.isDetailReplacementPreset
? ("spu" as const)
: skuReplacementQueryType,
selectedCandidateId: isDetailReplacementPreset
? detailReplacementSelectedCandidateId || null
: skuReplacementSelectedCandidateId || null,
: transportState.skuReplacementQueryType,
selectedCandidateId: transportState.isDetailReplacementPreset
? transportState.detailReplacementSelectedCandidateId || null
: transportState.skuReplacementSelectedCandidateId || null,
references: (
isDetailReplacementPreset
? detailReplacementReferenceCards
: skuReplacementReferenceCards
transportState.isDetailReplacementPreset
? transportState.detailReplacementReferenceCards
: transportState.skuReplacementReferenceCards
)
.filter((item) => Boolean(String(item.imageUrl || "").trim()))
.map((item) => ({
@ -820,10 +872,10 @@ export function AgentGenerationWorkspaceDarkV2({
candidateId: item.candidateId || null,
sortOrder: item.sortOrder ?? 0,
assignedProductIndex:
selectedProductAttachments.length > 0
transportState.selectedProductAttachmentCount > 0
? Math.min(
item.assignedProductIndex ?? 0,
Math.max(selectedProductAttachments.length - 1, 0)
Math.max(transportState.selectedProductAttachmentCount - 1, 0)
)
: null,
})),
@ -834,10 +886,10 @@ export function AgentGenerationWorkspaceDarkV2({
id: rawChatId,
message: request.messages.at(-1),
hiddenPrompt: hiddenPromptRef.current || undefined,
agentPresetId: selectedAgentPresetId || undefined,
selectedChatModel: selectedModelId,
agentPresetId: transportState.selectedAgentPresetId || undefined,
selectedChatModel: transportState.selectedModelId,
selectedVisibilityType: "private",
imageParams,
imageParams: transportState.imageParams,
agentModePayload: replacementModePayload,
},
};

View File

@ -329,6 +329,24 @@ export function AgentGenerationWorkspaceNew({
() => selectableModels.find((model) => model.id === selectedModelId) || selectableModels[0],
[selectableModels, selectedModelId]
);
const transportStateRef = useRef<{
selectedAgentPresetId: string | null;
selectedModelId: string;
imageParams: ImageGenerationParams;
}>({
selectedAgentPresetId: null,
selectedModelId: "auto",
imageParams: {
aspectRatio: "auto",
imageSize: "2K",
imageCount: 1,
},
});
transportStateRef.current = {
selectedAgentPresetId: selectedAgentPresetId || null,
selectedModelId,
imageParams,
};
const { messages, setMessages, sendMessage, status } = useChat<ChatMessage>({
id: chatId,
@ -339,15 +357,16 @@ export function AgentGenerationWorkspaceNew({
api: "/api/chat",
fetch: fetchWithErrorHandlers,
prepareSendMessagesRequest(request) {
const transportState = transportStateRef.current;
return {
body: {
id: rawChatId,
message: request.messages.at(-1),
hiddenPrompt: hiddenPromptRef.current || undefined,
agentPresetId: selectedAgentPresetId || undefined,
selectedChatModel: selectedModelId,
agentPresetId: transportState.selectedAgentPresetId || undefined,
selectedChatModel: transportState.selectedModelId,
selectedVisibilityType: "private",
imageParams,
imageParams: transportState.imageParams,
},
};
},