@@ -136,8 +136,8 @@ local function create_state(out, base_state)
136136end
137137
138138--- Add message using centralized state
139- --- @param data table
140- --- @param opts table
139+ --- @param data { content ?: string , role ?: string , reasoning ?: { content : string } }
140+ --- @param opts ? { type ?: string , force_role ?: boolean , insert_at ?: number , status ?: string , _icon_info ?: table , virt_text_pos ?: string , fold_info ?: table , state ?: table }
141141--- @return number,number | nil
142142function Builder :add_message (data , opts )
143143 opts = opts or {}
@@ -197,7 +197,9 @@ function Builder:add_message(data, opts)
197197
198198 local insert_line , icon_id
199199 if not vim .tbl_isempty (lines ) then
200- insert_line , icon_id = self :_write_to_buffer (lines , opts , fold_info , state )
200+ opts .fold_info = fold_info
201+ opts .state = state
202+ insert_line , icon_id = self :_write_to_buffer (lines , opts )
201203 end
202204
203205 if current_type then
@@ -225,24 +227,24 @@ function Builder:add_message(data, opts)
225227end
226228
227229--- Determine if we should start a new block under the header
228- --- @param opts table
230+ --- @param opts { type ?: string }
229231--- @param state table
230232--- @return boolean
231233function Builder :_should_start_new_block (opts , state )
232234 return opts .type ~= nil and opts .type ~= state .last_type
233235end
234236
235237--- Check if we need to add a header to the chat buffer
236- --- @param data table
237- --- @param opts table
238+ --- @param data { role ?: string }
239+ --- @param opts { force_role ?: boolean }
238240--- @param state table
239241--- @return boolean
240242function Builder :_should_add_header (data , opts , state )
241243 return (data .role and data .role ~= state .last_role ) or (opts and opts .force_role )
242244end
243245
244246--- Add appropriate spacing before header
245- --- @param lines table
247+ --- @param lines string[]
246248--- @return nil
247249function Builder :_add_header_spacing (lines )
248250 table.insert (lines , " " )
@@ -263,12 +265,13 @@ function Builder:_get_formatter(data, opts)
263265end
264266
265267--- Write lines to buffer with all the buffer management
266- --- @param lines table
267- --- @param opts table
268- --- @param fold_info table | nil
269- --- @param state table
270- --- @return number The line number where the content was written and the extmark id of any icon applied
271- function Builder :_write_to_buffer (lines , opts , fold_info , state )
268+ --- @param lines string[]
269+ --- @param opts { insert_at ?: number , _icon_info ?: table , virt_text_pos ?: string , fold_info ?: table , state ?: table }
270+ --- @return number , number | nil
271+ function Builder :_write_to_buffer (lines , opts )
272+ local state = opts .state
273+ local fold_info = opts .fold_info
274+
272275 self .chat .ui :unlock_buf ()
273276 local last_line , last_column , line_count = self .chat .ui :last ()
274277
345348--- Update a specific line in the chat buffer
346349--- @param line_number number The line number to update (1-based )
347350--- @param content string The new content for the line
348- --- @param opts ? table Optional parameters
351+ --- @param opts ? { status ?: string , icon_id ?: number , priority ?: number , virt_text_pos ?: string }
349352--- @return boolean success Whether the update was successful
350353--- @return number | nil icon_id The new icon extmark ID , if an icon was placed
351354function Builder :update_line (line_number , content , opts )
0 commit comments