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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const typedPart = part as {
|
||||||
|
type: string;
|
||||||
|
url?: string;
|
||||||
|
image?: string;
|
||||||
|
image_url?: { url?: string };
|
||||||
|
data?: string;
|
||||||
|
};
|
||||||
const candidateImageUrl =
|
const candidateImageUrl =
|
||||||
part.type === "file"
|
typedPart.type === "file"
|
||||||
? part.url || (part as { data?: string | undefined }).data
|
? typedPart.url || typedPart.data
|
||||||
: part.type === "image"
|
: typedPart.type === "image"
|
||||||
? part.image || part.url
|
? typedPart.image || typedPart.url
|
||||||
: part.type === "image_url"
|
: typedPart.type === "image_url"
|
||||||
? part.image_url?.url || part.url
|
? typedPart.image_url?.url || typedPart.url
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (typeof candidateImageUrl !== "string" || !candidateImageUrl.trim()) {
|
if (typeof candidateImageUrl !== "string" || !candidateImageUrl.trim()) {
|
||||||
@ -625,7 +632,7 @@ export async function convertMessagesWithImages(
|
|||||||
const normalizedImageUrl = candidateImageUrl.trim();
|
const normalizedImageUrl = candidateImageUrl.trim();
|
||||||
|
|
||||||
// 兼容 file/image/image_url 三类输入;Gemini 内部会将图片交给 S3 后再请求生图网关。
|
// 兼容 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({
|
content.push({
|
||||||
type: "image_url",
|
type: "image_url",
|
||||||
image_url: {
|
image_url: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user