improve current upload target resolution

This commit is contained in:
134 2026-06-24 20:08:24 +08:00
parent c7e4553c45
commit f0e17dfffe

View File

@ -103,6 +103,8 @@ function collectOrdinalIndexes(text: string): number[] {
const chineseOrdinalPattern =
/第\s*([一二三四五六七八九十两\d]+)\s*(?:张|个|幅)?\s*(?:图|图片|照片)?/gi;
const numberedImagePattern = /(?:图|图片|照片|image|photo|reference)\s*([1-9]\d*)\b/gi;
const compactChineseImagePattern =
/(?:图片|照片|图)\s*([一二两三四五六七八九十])(?=\s*(?:的|上|中|里|内|和|与|及|、|,|,|。|;|;|$))/g;
const englishOrdinals: Array<{ index: number; pattern: RegExp }> = [
{ index: 0, pattern: /\b(?:first|1st)\s+(?:image|photo|reference)\b/i },
{ index: 1, pattern: /\b(?:second|2nd)\s+(?:image|photo|reference)\b/i },
@ -122,6 +124,10 @@ function collectOrdinalIndexes(text: string): number[] {
const numeric = Number.parseInt(match[1] || "", 10);
if (Number.isFinite(numeric) && numeric > 0) indexes.add(numeric - 1);
}
for (const match of normalizedText.matchAll(compactChineseImagePattern)) {
const numeric = chineseNumberToInt(match[1] || "");
if (numeric && numeric > 0) indexes.add(numeric - 1);
}
for (const item of englishOrdinals) {
if (item.pattern.test(normalizedText)) indexes.add(item.index);
}
@ -261,6 +267,34 @@ export function resolveTargetAssets(
);
})();
const currentOrdinalRefs = pickByOrdinal(text, currentRefs);
if (currentOrdinalRefs.length > 0) {
return buildResolvedTargetAssets({
targetRefs: currentOrdinalRefs,
candidateRefs,
resolutionMode: "current_upload",
confidence: currentOrdinalRefs.length > 1 ? 96 : 94,
needsClarification: false,
reason:
currentOrdinalRefs.length > 1
? "根据用户文本中的多个序号定位到本轮上传的多张图片"
: "根据用户文本中的序号定位到本轮上传图片",
fromHistory: false,
});
}
if (currentRefs.length > 0) {
return buildResolvedTargetAssets({
targetRefs: currentRefs,
candidateRefs,
resolutionMode: "current_upload",
confidence: 93,
needsClarification: false,
reason: "本轮消息包含图片输入,默认优先处理当前上传图片",
fromHistory: false,
});
}
const ordinalRefs = pickByOrdinal(text, canvasRefs);
if (ordinalRefs.length > 0) {
return buildResolvedTargetAssets({
@ -350,18 +384,6 @@ export function resolveTargetAssets(
});
}
if (currentRefs.length > 0) {
return buildResolvedTargetAssets({
targetRefs: currentRefs,
candidateRefs,
resolutionMode: "current_upload",
confidence: 93,
needsClarification: false,
reason: "本轮消息包含图片输入,默认优先处理当前上传图片",
fromHistory: false,
});
}
if (DEICTIC_TARGET_REGEX.test(text)) {
if (selectedRefs.length > 0) {
return buildResolvedTargetAssets({