#!/usr/bin/env python3
"""Remove provider override, keep only reasoning.effort=none."""

import subprocess

# Read current file from container
r = subprocess.run(['docker', 'exec', 'graphiti-service', 'cat', '/app/llm_call_worker.py'],
                   capture_output=True, text=True)
src = r.stdout

# Replace the double extra_body with single reasoning-only version
old_extra = """extra_body={'provider': {'order': ['Alibaba']},
                        'reasoning': {'effort': 'none'}},\n        )"""

new_extra = """extra_body={'reasoning': {'effort': 'none'}},\n        )"""

if old_extra in src:
    src = src.replace(old_extra, new_extra)
    print("✅ Removed Alibaba provider, kept reasoning.effort=none")
    
    # Write to container
    w = subprocess.run(['docker', 'exec', '-i', 'graphiti-service', 'sh', '-c',
                       'cat > /app/llm_call_worker.py'],
                      input=src.encode(), capture_output=True)
    
    if w.returncode == 0:
        print("✅ Patch written to container")
        
        # Sync host source
        with open('/opt/struktur/graphiti/service/llm_call_worker.py', 'w') as f:
            f.write(src)
        print("✅ Synced to host (recreate-fest)")
        
        # Verify
        lines = src.split('\n')
        print("\n=== Verifying ===")
        for i, line in enumerate(lines):
            if 'extra_body' in line or 'reasoning' in line:
                print(f"{i}: {line}")
    else:
        print(f"❌ Write failed: {w.stderr.decode()}")
        raise SystemExit(1)
else:
    print("❌ Pattern not found!")
    print("Current extra_body section:")
    lines = src.split('\n')
    for i, line in enumerate(lines):
        if 'extra_body' in line or 'reasoning' in line or ')' in line:
            print(f"{i}: {line}")
    raise SystemExit(1)
