File size: 1,040 Bytes
8d57f39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
with open('app.py', 'r', encoding='utf-8') as f:
    content = f.read()

# Fix 1: JS sends 'action' but backend now expects 'fixed_sql'
old1 = "body: JSON.stringify({{action: agentSQL, explanation: ''}})"
new1 = "body: JSON.stringify({{fixed_sql: agentSQL, explanation: ''}})"
content = content.replace(old1, new1)

# Fix 2: reward.toFixed(2) crashes when reward is undefined - add null guard
old2 = 'const reward = data.reward;'
new2 = 'const reward = (data.reward != null) ? data.reward : 0.0;'
content = content.replace(old2, new2)

# Fix 3: data.state?.step_count -> data.observation?.step_count (renamed key)
old3 = "data.state?.step_count ?? '?'"
new3 = "data.observation?.step_count ?? '?'"
content = content.replace(old3, new3)

with open('app.py', 'w', encoding='utf-8') as f:
    f.write(content)

print('Done! Verifying...')
print('fixed_sql patch:', content.count('fixed_sql: agentSQL'))
print('null guard patch:', content.count('data.reward != null'))
print('observation patch:', content.count('data.observation?.step_count'))