feat(ipc): add request_confirmation to ApiHookClient
This commit is contained in:
@@ -21,13 +21,13 @@ class ApiHookClient:
|
||||
time.sleep(0.1)
|
||||
return False
|
||||
|
||||
def _make_request(self, method, endpoint, data=None):
|
||||
def _make_request(self, method, endpoint, data=None, timeout=None):
|
||||
url = f"{self.base_url}{endpoint}"
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
last_exception = None
|
||||
# Lower request timeout for local server
|
||||
req_timeout = 0.5
|
||||
# Lower request timeout for local server by default
|
||||
req_timeout = timeout if timeout is not None else 0.5
|
||||
|
||||
for attempt in range(self.max_retries + 1):
|
||||
try:
|
||||
@@ -37,7 +37,7 @@ class ApiHookClient:
|
||||
response = requests.post(url, json=data, headers=headers, timeout=req_timeout)
|
||||
else:
|
||||
raise ValueError(f"Unsupported HTTP method: {method}")
|
||||
|
||||
|
||||
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
|
||||
return response.json()
|
||||
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e:
|
||||
@@ -122,7 +122,7 @@ class ApiHookClient:
|
||||
return v
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
# Try GET fallback
|
||||
res = self._make_request('GET', f'/api/gui/value/{item}')
|
||||
@@ -207,3 +207,11 @@ class ApiHookClient:
|
||||
def reset_session(self):
|
||||
"""Simulates clicking the 'Reset Session' button in the GUI."""
|
||||
return self.click("btn_reset")
|
||||
|
||||
def request_confirmation(self, tool_name, args):
|
||||
"""Asks the user for confirmation via the GUI (blocking call)."""
|
||||
# Using a long timeout as this waits for human input (60 seconds)
|
||||
res = self._make_request('POST', '/api/ask',
|
||||
data={'type': 'tool_approval', 'tool': tool_name, 'args': args},
|
||||
timeout=60.0)
|
||||
return res.get('response')
|
||||
|
||||
Reference in New Issue
Block a user