From f0e17dfffef8c1c5b1e912f7cc220c94d844e481 Mon Sep 17 00:00:00 2001 From: 134 Date: Wed, 24 Jun 2026 20:08:24 +0800 Subject: [PATCH] improve current upload target resolution --- lib/ai/context-memory/target-resolution.ts | 46 ++++++++++++++++------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/lib/ai/context-memory/target-resolution.ts b/lib/ai/context-memory/target-resolution.ts index 5ce82982b..e0d8f8064 100644 --- a/lib/ai/context-memory/target-resolution.ts +++ b/lib/ai/context-memory/target-resolution.ts @@ -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({