"""Selected GPT-6 Sol/Luna compatibility checks as of 2026-09-23.
Not a complete JSON/API validator. No network, account or model testing.
"""
import json,sys
EFFORT={'none','low','medium','high','xhigh','max'}
def check(endpoint,p):
 errors=[]
 if endpoint not in ('responses','chat'):return ['Endpoint must be responses or chat']
 if not isinstance(p,dict):return ['Payload must be an object']
 if p.get('model') not in ('gpt-6-sol','gpt-6-luna'):errors.append('Use gpt-6-sol or gpt-6-luna for this checker')
 if endpoint=='responses':
  if 'reasoning_effort' in p:errors.append('Responses uses reasoning.effort, not reasoning_effort')
  reasoning=p.get('reasoning',{})
  if not isinstance(reasoning,dict):errors.append('reasoning must be an object');reasoning={}
  effort=reasoning.get('effort','medium')
  if 'input' not in p:errors.append('Responses example requires input')
 else:
  if 'reasoning' in p:errors.append('Chat uses reasoning_effort, not a reasoning object')
  effort=p.get('reasoning_effort','medium')
  if not isinstance(p.get('messages'),list):errors.append('Chat example requires a messages list')
 if not isinstance(effort,str) or effort not in EFFORT:errors.append('Unsupported effort for this checker')
 tools=p.get('tools',[])
 if not isinstance(tools,list):errors.append('tools must be a list');tools=[]
 for tool in tools:
  if not isinstance(tool,dict):errors.append('Each tool must be an object');continue
  if tool.get('type')=='function':
   if endpoint=='chat':
    if effort!='none':errors.append('Chat function calling requires reasoning_effort none')
    if not isinstance(tool.get('function'),dict):errors.append('Chat function definition belongs inside function')
   elif 'function' in tool or not tool.get('name'):errors.append('Responses function uses top-level name, not nested function')
 if effort!='none':
  for name in ('temperature','top_p','top_logprobs'):
   if name in p:errors.append('Remove '+name+' when reasoning is not none')
  if endpoint=='chat' and 'logprobs' in p:errors.append('Remove logprobs for reasoning in Chat')
  inc=p.get('include',[])
  if endpoint=='responses' and isinstance(inc,list) and 'message.output_text.logprobs' in inc:errors.append('Remove message.output_text.logprobs from include')
 return errors
if __name__=='__main__':
 if len(sys.argv)!=3:raise SystemExit('Usage: python3 check_request.py responses|chat file.json')
 try:
  with open(sys.argv[2],encoding='utf-8') as f:payload=json.load(f)
 except (OSError,ValueError) as exc:raise SystemExit(str(exc))
 errors=check(sys.argv[1],payload)
 print(json.dumps({'passed_selected_checks':not errors,'errors':errors,'scope':'local selected rules only; no API request'},indent=2))
 raise SystemExit(1 if errors else 0)
