filepath = "/root/efesto-qa/source/backend/src/services/agentService.js"

with open(filepath, "r") as f:
    content = f.read()

old = """const askedForPhotos = /(?:quiero|envía|envíame|manda|muéstra|muestrame|puedo ver|ver|pásame|pasame).*(?:foto|imagen|image)/i.test(messageText)
        || /(?:foto|fotos|imagen|imagenes)/i.test(messageText);"""

# Try simpler match first
if old not in content:
    old = 'const askedForPhotos = /(?:quiero'
    idx = content.find(old)
    if idx > 0:
        end = content.find(';', idx) + 1
        old = content[idx:end]

new = """const askedForPhotos = /fotos?|imagene?s?|images?|muestram|muéstram|envíam|mandam|enséñam|enseñam|ver.*propiedad|tienes.*foto|puedo ver/i.test(messageText);"""

if old in content:
    content = content.replace(old, new)
    with open(filepath, "w") as f:
        f.write(content)
    print("OK - regex fixed")
else:
    # Find the line and show it
    for i, line in enumerate(content.split('\n')):
        if 'askedForPhotos' in line and 'const' in line:
            print(f"Line {i}: {line[:150]}")
