mirror of
https://github.com/sst/opencode.git
synced 2025-08-10 00:08:05 +00:00
handle errors correctly in the other tools
This commit is contained in:
parent
921f5ee5bd
commit
0b3e5f5bd4
8 changed files with 72 additions and 26 deletions
|
@ -63,6 +63,11 @@ type GlobParams struct {
|
|||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
type GlobMetadata struct {
|
||||
NumberOfFiles int `json:"number_of_files"`
|
||||
Truncated bool `json:"truncated"`
|
||||
}
|
||||
|
||||
type globTool struct{}
|
||||
|
||||
func NewGlobTool() BaseTool {
|
||||
|
@ -104,7 +109,7 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
|
|||
|
||||
files, truncated, err := globFiles(params.Pattern, searchPath, 100)
|
||||
if err != nil {
|
||||
return NewTextErrorResponse(fmt.Sprintf("error performing glob search: %s", err)), nil
|
||||
return ToolResponse{}, fmt.Errorf("error finding files: %w", err)
|
||||
}
|
||||
|
||||
var output string
|
||||
|
@ -117,7 +122,13 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
|
|||
}
|
||||
}
|
||||
|
||||
return NewTextResponse(output), nil
|
||||
return WithResponseMetadata(
|
||||
NewTextResponse(output),
|
||||
GlobMetadata{
|
||||
NumberOfFiles: len(files),
|
||||
Truncated: truncated,
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue