# aiagent.py - Agent logic (raw OpenAI-compatible API). UI is in app_pyobjc2.py.
# Coordinator: re-exports from agent_loop, agent_worker, agent_chat_html, agent_research; holds checkpointer state for app.
from __future__ import annotations

import os

from persistence import MUGI_DIR

from agent_chat_html import get_chat_html, THEME
from agent_loop import (
    CHATS_DB_DIR,
    CHATS_DB_FILENAME,
    CHECKPOINT_DB_FILENAME,
    APP_PREFS_FILENAME,
    DEFAULT_BACKEND_BASE_URL,
    get_backend_base_url,
    get_llmster_model,
    get_vision_image_format,
    get_state,
    run_raw_agent,
    normalize_stream_text,
    _create_agent,
    agent,
    MemorySaver,
)
from agent_research import (
    MIN_SCRATCH_APPENDS_FOR_REPORT,
    MIN_SCRATCH_FILE_SIZE,
    _research_report_gate_block_reason,
)
from agent_worker import (
    AgentWorker,
    _extract_output_path_from_tool_result,
    _short_path,
    _tool_status_for_chat,
    _image_paths_to_data_urls,
)

# App-managed checkpointer state (app_pyobjc2 sets these and replaces agent)
_checkpoint_path = os.path.join(CHATS_DB_DIR, CHECKPOINT_DB_FILENAME)
_checkpointer = None
_SqliteSaver = None

# ============================================================================
# Raw OpenAI-compatible agent; no LangGraph. Run app_pyobjc2.py for the UI.
if __name__ == "__main__":
    print("Raw agent (no LangGraph). Run app_pyobjc2.py for the UI.", flush=True)
