Skip to content

feat: add support for sub-tool option #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Opts struct {
CacheDir string `json:"cacheDir"`
Quiet bool `json:"quiet"`
Chdir string `json:"chdir"`
SubTool string `json:"subTool"`
}

func (o Opts) toArgs() []string {
Expand All @@ -28,6 +29,9 @@ func (o Opts) toArgs() []string {
if o.Chdir != "" {
args = append(args, "--chdir="+o.Chdir)
}
if o.SubTool != "" {
args = append(args, "--sub-tool="+o.SubTool)
}
return append(args, "--quiet="+fmt.Sprint(o.Quiet))
}

Expand Down
36 changes: 36 additions & 0 deletions exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,42 @@ func TestExecWithToolList(t *testing.T) {
}
}

func TestExecWithToolListAndSubTool(t *testing.T) {
shebang := "#!/bin/bash"
if runtime.GOOS == "windows" {
shebang = "#!/usr/bin/env powershell.exe"
}
tools := []fmt.Stringer{
&Tool{
Tools: []string{"echo"},
Instructions: "echo hello there",
},
&Tool{
Name: "other",
Tools: []string{"echo"},
Instructions: "echo hello somewhere else",
},
&Tool{
Name: "echo",
Tools: []string{"sys.exec"},
Description: "Echoes the input",
Args: map[string]string{
"input": "The string input to echo",
},
Instructions: shebang + "\n echo ${input}",
},
}

out, err := ExecTool(context.Background(), Opts{SubTool: "other"}, tools...)
if err != nil {
t.Errorf("Error executing tool: %v", err)
}

if !strings.Contains(out, "hello somewhere else") {
t.Errorf("Unexpected output: %s", out)
}
}

func TestStreamExec(t *testing.T) {
tool := &FreeForm{Content: "What is the capital of the united states?"}

Expand Down