fix(logic): ignore reference directives when checking for prompt text

Strip inline image tokens and reference directive URLs before deciding
whether a prompt carries real user text, so a reference-only prompt is
still treated as empty while text around references counts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-08 16:17:59 +08:00
parent 68427ad91a
commit ba4db85241
2 changed files with 32 additions and 0 deletions
@@ -2,11 +2,17 @@ package logic
import (
"fmt"
"regexp"
"strings"
"img_infinite_canvas/internal/domain/design"
)
var (
promptReferenceDirectivePattern = regexp.MustCompile(`(?i)(?:参考图|reference image)\s*\d*\s*(?:[(][^)\n]+[)])?\s*[:]\s*(?:https?://[^\s\],。]+|data:image/[^\s\],。]+|/[^\s\],。]+)`)
promptImageTokenPattern = regexp.MustCompile(`\[@image:#\d+:[^:\]]+:(?:\[[^\]]+\]\((?:[^)]+)\)|[^\]]+)\]`)
)
func validateRequiredPrompt(prompt string, allowEmpty bool) error {
if allowEmpty {
return nil
@@ -18,6 +24,8 @@ func validateRequiredPrompt(prompt string, allowEmpty bool) error {
}
func hasRequiredPromptText(prompt string) bool {
prompt = promptImageTokenPattern.ReplaceAllString(prompt, " ")
prompt = promptReferenceDirectivePattern.ReplaceAllString(prompt, " ")
for _, line := range strings.Split(prompt, "\n") {
line = strings.TrimSpace(strings.ReplaceAll(line, "\u00a0", " "))
if line == "" || isPromptReferenceDirective(line) {