Skip to content

Commit 8f17112

Browse files
committed
feat: add support for sub-tool option
Signed-off-by: Donnie Adams <[email protected]>
1 parent 52306d5 commit 8f17112

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

exec.go

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Opts struct {
1515
CacheDir string `json:"cacheDir"`
1616
Quiet bool `json:"quiet"`
1717
Chdir string `json:"chdir"`
18+
SubTool string `json:"subTool"`
1819
}
1920

2021
func (o Opts) toArgs() []string {
@@ -28,6 +29,9 @@ func (o Opts) toArgs() []string {
2829
if o.Chdir != "" {
2930
args = append(args, "--chdir="+o.Chdir)
3031
}
32+
if o.SubTool != "" {
33+
args = append(args, "--sub-tool="+o.SubTool)
34+
}
3135
return append(args, "--quiet="+fmt.Sprint(o.Quiet))
3236
}
3337

exec_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,42 @@ func TestExecWithToolList(t *testing.T) {
135135
}
136136
}
137137

138+
func TestExecWithToolListAndSubTool(t *testing.T) {
139+
shebang := "#!/bin/bash"
140+
if runtime.GOOS == "windows" {
141+
shebang = "#!/usr/bin/env powershell.exe"
142+
}
143+
tools := []fmt.Stringer{
144+
&Tool{
145+
Tools: []string{"echo"},
146+
Instructions: "echo hello there",
147+
},
148+
&Tool{
149+
Name: "other",
150+
Tools: []string{"echo"},
151+
Instructions: "echo hello somewhere else",
152+
},
153+
&Tool{
154+
Name: "echo",
155+
Tools: []string{"sys.exec"},
156+
Description: "Echoes the input",
157+
Args: map[string]string{
158+
"input": "The string input to echo",
159+
},
160+
Instructions: shebang + "\n echo ${input}",
161+
},
162+
}
163+
164+
out, err := ExecTool(context.Background(), Opts{SubTool: "other"}, tools...)
165+
if err != nil {
166+
t.Errorf("Error executing tool: %v", err)
167+
}
168+
169+
if !strings.Contains(out, "hello somewhere else") {
170+
t.Errorf("Unexpected output: %s", out)
171+
}
172+
}
173+
138174
func TestStreamExec(t *testing.T) {
139175
tool := &FreeForm{Content: "What is the capital of the united states?"}
140176

0 commit comments

Comments
 (0)