Skip to content

Commit

Permalink
Fix: Fix tool reference to properly index gpt files (#1731)
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <[email protected]>
  • Loading branch information
StrongMonkey authored Feb 14, 2025
1 parent c505de6 commit 1e2ab78
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/tools/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tools
import (
"context"
"fmt"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -51,12 +52,29 @@ func ResolveToolReferences(ctx context.Context, gptClient *gptscript.GPTScript,
return result, nil
}

for _, peerToolID := range tool.LocalTools {
var exportToolIDs []string
for _, export := range tool.Export {
tools := tool.ToolMapping[export]
for _, t := range tools {
exportToolIDs = append(exportToolIDs, t.ToolID)
}
}

for _, peerToolID := range exportToolIDs {
if peerToolID == prg.EntryToolID {
continue
}

peerTool := prg.ToolSet[peerToolID]
ref, _, _ := strings.Cut(peerToolID, ":")
toolRef := reference
if strings.HasPrefix(ref, "./") || strings.HasPrefix(ref, "../") {
relPath, err := filepath.Rel(peerTool.WorkingDir, ref)
if err != nil {
return nil, err
}
toolRef = filepath.Join(toolRef, relPath)
}
if isValidTool(peerTool) {
toolName := resolveToolReferenceName(toolType, false, peerTool.MetaData["category"] == "Capability", name, peerTool.Name)
result = append(result, &v1.ToolReference{
Expand All @@ -68,7 +86,7 @@ func ResolveToolReferences(ctx context.Context, gptClient *gptscript.GPTScript,
},
Spec: v1.ToolReferenceSpec{
Type: toolType,
Reference: fmt.Sprintf("%s from %s", peerTool.Name, reference),
Reference: fmt.Sprintf("%s from %s", peerTool.Name, toolRef),
Builtin: builtin,
BundleToolName: entryTool.Name,
},
Expand Down

0 comments on commit 1e2ab78

Please sign in to comment.