feat: streaming attempt completion (#2113)

This commit is contained in:
yetone
2025-06-02 21:21:05 +08:00
committed by GitHub
parent 1c4e062199
commit 647a459a2b
3 changed files with 37 additions and 28 deletions

View File

@@ -1,8 +1,9 @@
local Base = require("avante.llm_tools.base")
local Config = require("avante.config")
local HistoryMessage = require("avante.history_message")
local Highlights = require("avante.highlights")
local Line = require("avante.ui.line")
---@alias AttemptCompletionInput {result: string, command?: string}
---@alias AttemptCompletionInput {result: string, command?: string, streaming?: boolean}
---@class AvanteLLMTool
local M = setmetatable({}, Base)
@@ -54,7 +55,16 @@ M.returns = {
}
---@type AvanteLLMToolOnRender<AttemptCompletionInput>
function M.on_render() return {} end
function M.on_render(opts)
local lines = {}
table.insert(lines, Line:new({ { "✓ Task Completed", Highlights.AVANTE_TASK_COMPLETED } }))
local result = opts.result or ""
local text_lines = vim.split(result, "\n")
for _, text_line in ipairs(text_lines) do
table.insert(lines, Line:new({ { text_line } }))
end
return lines
end
---@type AvanteLLMToolFunc<AttemptCompletionInput>
function M.func(opts, on_log, on_complete, session_ctx)
@@ -62,13 +72,6 @@ function M.func(opts, on_log, on_complete, session_ctx)
local sidebar = require("avante").get()
if not sidebar then return false, "Avante sidebar not found" end
session_ctx.attempt_completion_is_called = true
local message = HistoryMessage:new({
role = "assistant",
content = opts.result,
}, {
just_for_display = true,
})
sidebar:add_history_messages({ message })
if opts.command and opts.command ~= "" and opts.command ~= vim.NIL then
require("avante.llm_tools.bash").func({ command = opts.command }, on_log, on_complete, session_ctx)
else