fix: fast-path pure greetings in agent mode
This commit is contained in:
parent
d1bcb7ce16
commit
5d3c7c1cdc
@ -1233,6 +1233,15 @@ function normalizeAssistantPartsForPersistence(parts: Array<Record<string, any>>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isPureGreetingTurnRequest(text: string): boolean {
|
||||||
|
const normalized = String(text || "").toLowerCase().replace(/\s+/g, "").trim();
|
||||||
|
if (!normalized) return false;
|
||||||
|
|
||||||
|
return /^(你好|您好|hello|hi|嗨|哈喽|在吗|早上好|中午好|下午好|晚上好|深夜好|谢谢|感谢|收到|好的|ok|okay|明白了|了解了)$/.test(
|
||||||
|
normalized,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function buildAgentToolImageMarkdown(params: {
|
function buildAgentToolImageMarkdown(params: {
|
||||||
originalUrl: string;
|
originalUrl: string;
|
||||||
thumbnailUrl?: string | null;
|
thumbnailUrl?: string | null;
|
||||||
@ -3149,6 +3158,49 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasCurrentMessageMediaInput = message.parts.some((part: any) =>
|
||||||
|
part?.type === "file" || part?.type === "image" || part?.type === "image_url"
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
shouldRunAgentConversation &&
|
||||||
|
isPureGreetingTurnRequest(requestTextContent) &&
|
||||||
|
!hasCurrentMessageMediaInput
|
||||||
|
) {
|
||||||
|
const session = await auth();
|
||||||
|
|
||||||
|
if (!session?.user) {
|
||||||
|
return new ChatSDKError("unauthorized:chat").toResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
const greetingMessage = "你好,我在。你可以直接告诉我想做什么:生图、修图、生成视频、分析图片都可以。";
|
||||||
|
const greetingStream = createUIMessageStream({
|
||||||
|
execute: async ({ writer }) => {
|
||||||
|
const messageId = generateUUID();
|
||||||
|
writeAssistantTextChunk(writer, greetingMessage, "greeting-fast-path", messageId);
|
||||||
|
|
||||||
|
await saveMessages({
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
id: messageId,
|
||||||
|
chatId: id,
|
||||||
|
role: "assistant",
|
||||||
|
parts: [{ type: "text", text: greetingMessage }],
|
||||||
|
attachments: [],
|
||||||
|
createdAt: new Date(),
|
||||||
|
videoStorageStatus: null,
|
||||||
|
temporaryVideoUrl: null,
|
||||||
|
permanentVideoUrl: null,
|
||||||
|
archivedAt: null,
|
||||||
|
videoMetadata: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return createSseResponse(greetingStream);
|
||||||
|
}
|
||||||
|
|
||||||
const allowAgentVideoGeneration =
|
const allowAgentVideoGeneration =
|
||||||
Boolean(requestBody.videoParams) || isVideoProviderType(requestedModelProviderType);
|
Boolean(requestBody.videoParams) || isVideoProviderType(requestedModelProviderType);
|
||||||
let smartAutoWorkflowDecision:
|
let smartAutoWorkflowDecision:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user