Add tool requires approval

This commit is contained in:
dwrz
2026-10-06 12:08:12 +00:00
parent bbfac06732
commit 83ff81dd2c
4 changed files with 66 additions and 11 deletions
+11 -7
View File
@@ -52,6 +52,9 @@ type Tool struct {
// used to validate a tool call before its arguments are rendered. See
// config.ToolConfig.Parameters.
Parameters map[string]any
// RequiresApproval reports whether calls to this tool must be approved
// by a user before the subprocess launches.
RequiresApproval bool
// timeout is the parsed execution duration limit.
timeout time.Duration
}
@@ -72,13 +75,14 @@ func NewTool(cfg config.ToolConfig) (*Tool, error) {
}
return &Tool{
Name: cfg.Name,
Description: cfg.Description,
Command: cfg.Command,
Arguments: cfg.Arguments,
Parameters: cfg.Parameters,
tmpl: templates,
timeout: cfg.Timeout,
Name: cfg.Name,
Description: cfg.Description,
Command: cfg.Command,
Arguments: cfg.Arguments,
Parameters: cfg.Parameters,
RequiresApproval: cfg.RequiresApproval,
tmpl: templates,
timeout: cfg.Timeout,
}, nil
}
+8 -4
View File
@@ -112,10 +112,11 @@ func TestTool_ParseArguments_ExecutionError(t *testing.T) {
func TestNewTool(t *testing.T) {
tool, err := NewTool(config.ToolConfig{
Name: "test",
Description: "desc",
Command: "ls",
Timeout: 10 * time.Second,
Name: "test",
Description: "desc",
Command: "ls",
Timeout: 10 * time.Second,
RequiresApproval: true,
})
if err != nil {
t.Fatalf("NewTool() error = %v", err)
@@ -123,6 +124,9 @@ func TestNewTool(t *testing.T) {
if tool.Name != "test" {
t.Errorf("Name = %q, want %q", tool.Name, "test")
}
if !tool.RequiresApproval {
t.Error("RequiresApproval = false, want true")
}
if tool.timeout != 10*time.Second {
t.Errorf("timeout = %v, want 10s", tool.timeout)
}