fix canvas agent image generation status
This commit is contained in:
parent
654829c4fd
commit
574c259812
@ -7896,6 +7896,32 @@ export async function POST(request: Request) {
|
|||||||
operationLabel: "agent-generate-image",
|
operationLabel: "agent-generate-image",
|
||||||
resultType: "image",
|
resultType: "image",
|
||||||
});
|
});
|
||||||
|
const directImageStatusPayload = {
|
||||||
|
providerType: requestedModelProviderType,
|
||||||
|
modelName: finalModelId,
|
||||||
|
imageCount:
|
||||||
|
effectiveImageParams?.imageCount ||
|
||||||
|
defaultImageQualityParams.imageCount ||
|
||||||
|
1,
|
||||||
|
};
|
||||||
|
const stopDirectImageKeepalive = startStreamKeepalive(
|
||||||
|
writer,
|
||||||
|
"agent:generate_image",
|
||||||
|
DEFAULT_STREAM_KEEPALIVE_INTERVAL_MS,
|
||||||
|
);
|
||||||
|
const stopDirectImageStatus =
|
||||||
|
contextPayload?.source === "canvas"
|
||||||
|
? setInterval(() => {
|
||||||
|
writeImageGenerationStatusChunk(
|
||||||
|
writer,
|
||||||
|
{
|
||||||
|
phase: "processing",
|
||||||
|
...directImageStatusPayload,
|
||||||
|
},
|
||||||
|
"agent:generate_image:status-processing-keepalive",
|
||||||
|
);
|
||||||
|
}, DEFAULT_STREAM_KEEPALIVE_INTERVAL_MS)
|
||||||
|
: null;
|
||||||
try {
|
try {
|
||||||
const directImageResult = await executeDirectAgentImageGeneration({
|
const directImageResult = await executeDirectAgentImageGeneration({
|
||||||
requestTextContent,
|
requestTextContent,
|
||||||
@ -8037,6 +8063,11 @@ export async function POST(request: Request) {
|
|||||||
"<!-- IMAGE_GENERATION_END -->",
|
"<!-- IMAGE_GENERATION_END -->",
|
||||||
"agent:generate_image:end-error",
|
"agent:generate_image:end-error",
|
||||||
);
|
);
|
||||||
|
} finally {
|
||||||
|
stopDirectImageKeepalive();
|
||||||
|
if (stopDirectImageStatus) {
|
||||||
|
clearInterval(stopDirectImageStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11006,16 +11006,20 @@ export function CanvasChatPanel({
|
|||||||
metadata: optimisticUserMetadata,
|
metadata: optimisticUserMetadata,
|
||||||
} as ChatMessage;
|
} as ChatMessage;
|
||||||
|
|
||||||
|
setMessages((previousMessages) =>
|
||||||
|
sortCanvasMessagesByCreatedAt([
|
||||||
|
...previousMessages.filter((message) => message.id !== userMessageId),
|
||||||
|
optimisticUserMessage,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
// 使用与 multimodal-input 相同的格式发送消息
|
// 使用与 multimodal-input 相同的格式发送消息
|
||||||
try {
|
try {
|
||||||
sendMessage(optimisticUserMessage as any);
|
sendMessage(optimisticUserMessage as any);
|
||||||
setMessages((previousMessages) =>
|
|
||||||
sortCanvasMessagesByCreatedAt([
|
|
||||||
...previousMessages.filter((message) => message.id !== userMessageId),
|
|
||||||
optimisticUserMessage,
|
|
||||||
])
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
setMessages((previousMessages) =>
|
||||||
|
previousMessages.filter((message) => message.id !== userMessageId)
|
||||||
|
);
|
||||||
releaseSendGuard(activeChatId);
|
releaseSendGuard(activeChatId);
|
||||||
if (shouldShowOptimisticImageGeneration) {
|
if (shouldShowOptimisticImageGeneration) {
|
||||||
clearStreamImageGenerationStateForChat(activeChatId);
|
clearStreamImageGenerationStateForChat(activeChatId);
|
||||||
@ -12010,8 +12014,10 @@ export function CanvasChatPanel({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
const shouldShowImageLoading =
|
const shouldShowImageLoading =
|
||||||
((hasGenerationStart && !hasGenerationEnd) || Boolean(streamImageGenerationState)) &&
|
Boolean(streamImageGenerationState) ||
|
||||||
!!currentModel;
|
(hasGenerationStart &&
|
||||||
|
!hasGenerationEnd &&
|
||||||
|
Boolean(currentModel || activeComposerMode === "agent"));
|
||||||
const hasActiveTypewriter = Object.keys(activeTypingSections).length > 0;
|
const hasActiveTypewriter = Object.keys(activeTypingSections).length > 0;
|
||||||
const shouldRenderImageLoading = shouldShowImageLoading && !hasActiveTypewriter;
|
const shouldRenderImageLoading = shouldShowImageLoading && !hasActiveTypewriter;
|
||||||
const loadingImageCount = streamImageGenerationState?.imageCount || imageParams.imageCount || 1;
|
const loadingImageCount = streamImageGenerationState?.imageCount || imageParams.imageCount || 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user