Skip to content

Commit 08215a2

Browse files
committed
decouple UI from server
Add a mediator that sits between the sidebar and the server that handles sending messages
1 parent f22df47 commit 08215a2

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lua/eca/init.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function M._init(id)
168168
local sidebar = M.sidebars[id]
169169

170170
if not sidebar then
171-
sidebar = Sidebar.new(id)
171+
sidebar = Sidebar.new(id, M.mediator)
172172
M.sidebars[id] = sidebar
173173
end
174174
M.current = { sidebar = sidebar }
@@ -241,11 +241,9 @@ function M.setup(opts)
241241
H.keymaps()
242242
H.signs()
243243

244-
-- Initialize status bar
245-
246244
-- Initialize the ECA server with callbacks
247245
M.server = Server.new()
248-
246+
M.mediator = require("eca.mediator").new(M.server)
249247
-- Start server automatically in background
250248
vim.defer_fn(function()
251249
M.server:start()

lua/eca/sidebar.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local Split = require("nui.split")
88
---@class eca.Sidebar
99
---@field public id integer The tab ID
1010
---@field public containers table<string, NuiSplit> The nui containers
11+
---@field mediator eca.Mediator mediator to send server requests to
1112
---@field private _initialized boolean Whether the sidebar has been initialized
1213
---@field private _current_response_buffer string Buffer for accumulating streaming response
1314
---@field private _is_streaming boolean Whether we're currently receiving a streaming response
@@ -34,10 +35,12 @@ local UI_ELEMENTS_HEIGHT = 2 -- Reserve space for statusline and tabline
3435
local SAFETY_MARGIN = 2 -- Extra margin to prevent "Not enough room" errors
3536

3637
---@param id integer Tab ID
38+
---@param mediator eca.Mediator
3739
---@return eca.Sidebar
38-
function M.new(id)
40+
function M.new(id, mediator)
3941
local instance = setmetatable({}, M)
4042
instance.id = id
43+
instance.mediator = mediator
4144
instance.containers = {}
4245
instance._initialized = false
4346
instance._current_response_buffer = ""
@@ -1163,7 +1166,7 @@ function M:_send_message(message)
11631166
if eca.server and eca.server:is_running() then
11641167
-- Include active contexts in the message
11651168
local contexts = self:get_contexts()
1166-
eca.server:send_request("chat/prompt", {
1169+
self.mediator:send("chat/prompt", {
11671170
chatId = self.id,
11681171
requestId = tostring(os.time()),
11691172
message = message,

lua/eca/types.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
---@alias eca.ToolCallDetails eca.FileChangedDetails
2424

25+
---TODO: flesh these out
26+
---@alias eca.MessageParams table
27+
---@alias eca.Message table
28+
2529
---@class eca.FileChangedDetails
2630
---@field type 'fileChange'
2731
---@field path string the file path of this file change

0 commit comments

Comments
 (0)