mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:14:34 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -80,9 +80,15 @@ export function detectImageReferences(prompt: string): DetectedImageRef[] {
|
||||
// Helper to add a path ref
|
||||
const addPathRef = (raw: string) => {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed || seen.has(trimmed.toLowerCase())) return;
|
||||
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) return;
|
||||
if (!isImageExtension(trimmed)) return;
|
||||
if (!trimmed || seen.has(trimmed.toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
|
||||
return;
|
||||
}
|
||||
if (!isImageExtension(trimmed)) {
|
||||
return;
|
||||
}
|
||||
seen.add(trimmed.toLowerCase());
|
||||
const resolved = trimmed.startsWith("~") ? resolveUserPath(trimmed) : trimmed;
|
||||
refs.push({ raw: trimmed, type: "path", resolved });
|
||||
@@ -118,7 +124,9 @@ export function detectImageReferences(prompt: string): DetectedImageRef[] {
|
||||
/\[Image:\s*source:\s*([^\]]+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif))\]/gi;
|
||||
while ((match = messageImagePattern.exec(prompt)) !== null) {
|
||||
const raw = match[1]?.trim();
|
||||
if (raw) addPathRef(raw);
|
||||
if (raw) {
|
||||
addPathRef(raw);
|
||||
}
|
||||
}
|
||||
|
||||
// Remote HTTP(S) URLs are intentionally ignored. Native image injection is local-only.
|
||||
@@ -127,7 +135,9 @@ export function detectImageReferences(prompt: string): DetectedImageRef[] {
|
||||
const fileUrlPattern = /file:\/\/[^\s<>"'`\]]+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif)/gi;
|
||||
while ((match = fileUrlPattern.exec(prompt)) !== null) {
|
||||
const raw = match[0];
|
||||
if (seen.has(raw.toLowerCase())) continue;
|
||||
if (seen.has(raw.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
seen.add(raw.toLowerCase());
|
||||
// Use fileURLToPath for proper handling (e.g., file://localhost/path)
|
||||
try {
|
||||
@@ -148,7 +158,9 @@ export function detectImageReferences(prompt: string): DetectedImageRef[] {
|
||||
/(?:^|\s|["'`(])((\.\.?\/|[~/])[^\s"'`()[\]]*\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif))/gi;
|
||||
while ((match = pathPattern.exec(prompt)) !== null) {
|
||||
// Use capture group 1 (the path without delimiter prefix); skip if undefined
|
||||
if (match[1]) addPathRef(match[1]);
|
||||
if (match[1]) {
|
||||
addPathRef(match[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return refs;
|
||||
@@ -267,9 +279,13 @@ function detectImagesFromHistory(messages: unknown[]): DetectedImageRef[] {
|
||||
const seen = new Set<string>();
|
||||
|
||||
const messageHasImageContent = (msg: unknown): boolean => {
|
||||
if (!msg || typeof msg !== "object") return false;
|
||||
if (!msg || typeof msg !== "object") {
|
||||
return false;
|
||||
}
|
||||
const content = (msg as { content?: unknown }).content;
|
||||
if (!Array.isArray(content)) return false;
|
||||
if (!Array.isArray(content)) {
|
||||
return false;
|
||||
}
|
||||
return content.some(
|
||||
(part) =>
|
||||
part != null && typeof part === "object" && (part as { type?: string }).type === "image",
|
||||
@@ -278,20 +294,30 @@ function detectImagesFromHistory(messages: unknown[]): DetectedImageRef[] {
|
||||
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
const msg = messages[i];
|
||||
if (!msg || typeof msg !== "object") continue;
|
||||
if (!msg || typeof msg !== "object") {
|
||||
continue;
|
||||
}
|
||||
const message = msg as { role?: string };
|
||||
// Only scan user messages for image references
|
||||
if (message.role !== "user") continue;
|
||||
if (message.role !== "user") {
|
||||
continue;
|
||||
}
|
||||
// Skip if message already has image content (prevents reloading each turn)
|
||||
if (messageHasImageContent(msg)) continue;
|
||||
if (messageHasImageContent(msg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const text = extractTextFromMessage(msg);
|
||||
if (!text) continue;
|
||||
if (!text) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const refs = detectImageReferences(text);
|
||||
for (const ref of refs) {
|
||||
const key = ref.resolved.toLowerCase();
|
||||
if (seen.has(key)) continue;
|
||||
if (seen.has(key)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(key);
|
||||
allRefs.push({ ...ref, messageIndex: i });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user