Data flow inversion:
- Add getHistoryForAgent() in conversations.ts — Agent now reads
history directly from SQLite instead of receiving it from frontend
- Remove historyMessages parameter from agent:runStream IPC chain,
add maxHistoryRounds for configurable context window
- Frontend (useAIChat.ts) pre-creates conversation before Agent call,
removes history message collection logic
IPC fixes:
- Restore llm:chat and llm:chatStream handlers using pi-ai's
completeSimple/streamSimple (P0-1: SQLLab compatibility)
- Send agent:complete with aborted flag in all abort paths to prevent
hanging Promises in renderer (P0-2)
- Fix createConversation parameter order to match preload/data layer
contract: (sessionId, title?) instead of (title, sessionId?) (P1)
Preload/frontend:
- Update preload API signatures and type declarations
- Use shared types for TokenUsage and AgentRuntimeStatus