"""JSONL and local HTTP entry points sharing the supported decision engine.""" import argparse from contextlib import contextmanager from datetime import datetime,timezone from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer import json from pathlib import Path import signal,sys,threading import urllib.error from .backend import Client,NativeServer from .decision import DecisionEngine CAPABILITIES=dict(api_version='1',input_fields=['state','question','options'],min_options=2,max_options=26, option_ids='opaque',numeric_values='parsed from option descriptions only',reasoning=False, modalities=['text'],agent_execution='experimental; not exposed by this HTTP service', compatibility='This is a decision API, not complete Jev/OpenJev API compatibility.') def server(engine,host='0.0.0.0',port=9304): slots=threading.BoundedSemaphore(2) class Handler(BaseHTTPRequestHandler): def log_message(self,*args):pass def send_json(self,status,payload): data=json.dumps(payload,ensure_ascii=False).encode() self.send_response(status);self.send_header('Content-Type','application/json');self.send_header('Content-Length',str(len(data)));self.end_headers() try:self.wfile.write(data) except (BrokenPipeError,ConnectionResetError):pass def do_GET(self): if self.path=='/health': try: engine.client.health() self.send_json(200,dict(status='ready',profile='base' if engine.client.adapter_id is None else 'adapter')) except (OSError,ValueError):self.send_json(503,dict(status='backend-unavailable')) elif self.path=='/v1/capabilities':self.send_json(200,CAPABILITIES) else:self.send_json(404,dict(error='Unknown endpoint')) def do_POST(self): if self.path!='/v1/decide':self.send_json(404,dict(error='Unknown endpoint'));return if not slots.acquire(blocking=False):self.send_json(503,dict(error='Decision worker and bounded queue are busy'));return try: self.connection.settimeout(125) length=int(self.headers.get('Content-Length','0')) if not 0