Skip to content

Commit

Permalink
fix: adjust relative credential paths for tool refs
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Jan 14, 2025
1 parent b45d616 commit c20ceba
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/controller/creds/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"path"
"path/filepath"
"slices"
"strings"

Expand Down Expand Up @@ -149,17 +150,26 @@ func toolRefsFromTools(parentTool gptscript.Tool, parentRef toolRef, tools []str

func fullToolPathName(parentRef toolRef, name string) string {
toolName, subTool := gtypes.SplitToolRef(name)

// If this tool's path is relative to its parent.
if strings.HasPrefix(toolName, ".") {
parentToolName, _ := gtypes.SplitToolRef(parentRef.Reference)
if !path.IsAbs(parentToolName) {
if !strings.HasPrefix(parentToolName, ".") {
parentToolName, _ = gtypes.SplitToolRef(parentRef.name)
parentRefToolName, _ := gtypes.SplitToolRef(parentRef.Reference)
parentToolName, _ := gtypes.SplitToolRef(parentRef.name)
if !path.IsAbs(parentRefToolName) {
if !strings.HasPrefix(parentRefToolName, ".") {
parentRefToolName = parentToolName
} else {
parentToolName = path.Join(parentRef.name, parentToolName)
if rel, err := filepath.Rel(parentToolName, parentRefToolName); err == nil {
parentRefToolName = rel
}
parentRefToolName = path.Join(parentToolName, parentRefToolName)
if rel, err := filepath.Rel(parentRefToolName, toolName); err == nil {
toolName = rel
}
}
}

refURL, err := url.Parse(parentToolName)
refURL, err := url.Parse(parentRefToolName)
if err != nil {
return ""
}
Expand Down

0 comments on commit c20ceba

Please sign in to comment.