-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: agent macro & rm ui.input for Prompt cmds
- Loading branch information
Showing
2 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local macro = require("gp.macro") | ||
local gp = require("gp") | ||
|
||
local M = {} | ||
|
||
---@type gp.Macro | ||
M = { | ||
name = "agent", | ||
description = "handles agent selection for commands", | ||
default = "", | ||
max_occurrences = 1, | ||
|
||
triggered = function(params) | ||
return params.cropped_line:match("@agent%s+%S*$") | ||
end, | ||
|
||
completion = function(params) | ||
if params.state.is_chat then | ||
return gp._chat_agents | ||
end | ||
return gp._command_agents | ||
end, | ||
|
||
parser = function(result) | ||
local template = result.template | ||
local s, e, value = template:find("@agent%s+(%S+)") | ||
if not value then | ||
return result | ||
end | ||
|
||
local placeholder = macro.generate_placeholder(M.name, value) | ||
result.template = template:sub(1, s - 2) .. placeholder .. template:sub(e + 1) | ||
if result.state.is_chat then | ||
result.state[M.name] = gp.get_chat_agent(value) | ||
else | ||
result.state[M.name] = gp.get_command_agent(value) | ||
end | ||
result.artifacts[placeholder] = "" | ||
return result | ||
end, | ||
} | ||
|
||
return M |