This commit is contained in:
2026-03-07 14:39:40 -05:00
parent a856d73f95
commit 6ab359deda
3 changed files with 53 additions and 9 deletions

View File

@@ -159,6 +159,7 @@ class AppController:
"output_tokens": 0,
"cache_read_input_tokens": 0,
"cache_creation_input_tokens": 0,
"total_tokens": 0,
"last_latency": 0.0
}
self.mma_tier_usage: Dict[str, Dict[str, Any]] = {
@@ -673,6 +674,21 @@ class AppController:
with self._disc_entries_lock:
self.disc_entries.append(item)
def _process_pending_tool_calls(self) -> bool:
"""Drains pending tool calls into the tool log. Returns True if any were processed."""
with self._pending_tool_calls_lock:
items = self._pending_tool_calls[:]
self._pending_tool_calls.clear()
if not items:
return False
for item in items:
self._append_tool_log(
item.get("script", ""),
item.get("result", ""),
source_tier=item.get("source_tier")
)
return True
def _test_callback_func_write_to_file(self, data: str) -> None:
"""A dummy function that a custom_callback would execute for testing."""
callback_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tests", "artifacts", "temp_callback_output.txt")
@@ -996,15 +1012,7 @@ class AppController:
def _handle_request_event(self, event: events.UserRequestEvent) -> None:
"""Processes a UserRequestEvent by calling the AI client."""
ai_client.set_current_tier(None) # Ensure main discussion is untagged
if self.ui_auto_add_history:
with self._pending_history_adds_lock:
self._pending_history_adds.append({
"role": "User",
"content": event.prompt,
"collapsed": True,
"ts": project_manager.now_ts()
})
# Clear response area for new turn
# Clear response area for new turn
self.ai_response = ""
csp = filter(bool, [self.ui_global_system_prompt.strip(), self.ui_project_system_prompt.strip()])
ai_client.set_custom_system_prompt("\n\n".join(csp))
@@ -1063,6 +1071,16 @@ class AppController:
"model": model
})
if kind == "request":
if self.ui_auto_add_history:
with self._pending_history_adds_lock:
self._pending_history_adds.append({
"role": "User",
"content": payload.get("message", ""),
"collapsed": payload.get("collapsed", False),
"ts": entry.get("ts", project_manager.now_ts())
})
if kind in ("tool_result", "tool_call"):
role = "Tool" if kind == "tool_result" else "Vendor API"
content = ""