fix: streaming diff debouncing (#2174)

This commit is contained in:
yetone
2025-06-06 15:47:31 +08:00
committed by GitHub
parent 12bdb66ea4
commit a537945573

View File

@@ -113,16 +113,15 @@ function M.func(opts, on_log, on_complete, session_ctx)
local is_streaming = opts.streaming or false
local current_timestamp = os.time()
if is_streaming then
session_ctx.prev_streaming_diff_timestamp_map = session_ctx.prev_streaming_diff_timestamp_map or {}
local prev_streaming_diff_timestamp = session_ctx.prev_streaming_diff_timestamp_map[opts.tool_use_id]
local current_timestamp = os.time()
if prev_streaming_diff_timestamp ~= nil then
if current_timestamp - prev_streaming_diff_timestamp < 2 then
return false, "Diff hasn't changed in the last 2 seconds"
end
end
session_ctx.prev_streaming_diff_timestamp_map[opts.tool_use_id] = current_timestamp
local streaming_diff_lines_count = Utils.count_lines(opts.diff)
session_ctx.streaming_diff_lines_count_history = session_ctx.streaming_diff_lines_count_history or {}
local prev_streaming_diff_lines_count = session_ctx.streaming_diff_lines_count_history[opts.tool_use_id]
@@ -180,6 +179,8 @@ function M.func(opts, on_log, on_complete, session_ctx)
return false, "No diff blocks found"
end
session_ctx.prev_streaming_diff_timestamp_map[opts.tool_use_id] = current_timestamp
local bufnr, err = Helpers.get_bufnr(abs_path)
if err then return false, err end