fix(chat): normalize image part fields for ts safety
This commit is contained in:
parent
09efe47f17
commit
74adb68d16
@ -609,13 +609,20 @@ export async function convertMessagesWithImages(
|
||||
continue;
|
||||
}
|
||||
|
||||
const typedPart = part as {
|
||||
type: string;
|
||||
url?: string;
|
||||
image?: string;
|
||||
image_url?: { url?: string };
|
||||
data?: string;
|
||||
};
|
||||
const candidateImageUrl =
|
||||
part.type === "file"
|
||||
? part.url || (part as { data?: string | undefined }).data
|
||||
: part.type === "image"
|
||||
? part.image || part.url
|
||||
: part.type === "image_url"
|
||||
? part.image_url?.url || part.url
|
||||
typedPart.type === "file"
|
||||
? typedPart.url || typedPart.data
|
||||
: typedPart.type === "image"
|
||||
? typedPart.image || typedPart.url
|
||||
: typedPart.type === "image_url"
|
||||
? typedPart.image_url?.url || typedPart.url
|
||||
: undefined;
|
||||
|
||||
if (typeof candidateImageUrl !== "string" || !candidateImageUrl.trim()) {
|
||||
@ -625,7 +632,7 @@ export async function convertMessagesWithImages(
|
||||
const normalizedImageUrl = candidateImageUrl.trim();
|
||||
|
||||
// 兼容 file/image/image_url 三类输入;Gemini 内部会将图片交给 S3 后再请求生图网关。
|
||||
if (part.type === "file" || part.type === "image" || part.type === "image_url") {
|
||||
if (typedPart.type === "file" || typedPart.type === "image" || typedPart.type === "image_url") {
|
||||
content.push({
|
||||
type: "image_url",
|
||||
image_url: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user