Enhance context handling in tool calls and improve path resolution
- Update `CallTool`, `CallTools`, and `CallToolsParallel` methods to pass the context as an additional argument, allowing for proper authorization propagation. - Modify `buildAuthorizedInfo` to include `TeamID` in the `AuthorizedInfo` struct. - Improve path resolution in `ResolvePathWithYaoRoot` to prioritize application root before falling back to the current working directory. - Adjust `LoadContextConfig` to read the context configuration file using the resolved path, enhancing file handling robustness.
This commit is contained in:
parent
406750c665
commit
48f8651db8
4 changed files with 22 additions and 9 deletions
|
|
@ -218,8 +218,8 @@ func (ctx *Context) CallTool(mcpID string, name string, arguments interface{}) (
|
|||
)
|
||||
}
|
||||
|
||||
// Call tool
|
||||
result, err := client.CallTool(ctx.Context, name, arguments)
|
||||
// Call tool (pass ctx as extraArgs for Process transport to propagate Authorized())
|
||||
result, err := client.CallTool(ctx.Context, name, arguments, ctx)
|
||||
if err != nil {
|
||||
if node != nil {
|
||||
node.Fail(err)
|
||||
|
|
@ -273,8 +273,8 @@ func (ctx *Context) CallTools(mcpID string, tools []types.ToolCall) (*types.Call
|
|||
)
|
||||
}
|
||||
|
||||
// Call tools sequentially
|
||||
result, err := client.CallTools(ctx.Context, tools)
|
||||
// Call tools sequentially (pass ctx as extraArgs for Process transport to propagate Authorized())
|
||||
result, err := client.CallTools(ctx.Context, tools, ctx)
|
||||
if err != nil {
|
||||
if node != nil {
|
||||
node.Fail(err)
|
||||
|
|
@ -328,8 +328,8 @@ func (ctx *Context) CallToolsParallel(mcpID string, tools []types.ToolCall) (*ty
|
|||
)
|
||||
}
|
||||
|
||||
// Call tools in parallel
|
||||
result, err := client.CallToolsParallel(ctx.Context, tools)
|
||||
// Call tools in parallel (pass ctx as extraArgs for Process transport to propagate Authorized())
|
||||
result, err := client.CallToolsParallel(ctx.Context, tools, ctx)
|
||||
if err != nil {
|
||||
if node != nil {
|
||||
node.Fail(err)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ func buildAuthorizedInfo(env *Environment) *types.AuthorizedInfo {
|
|||
authorized := &types.AuthorizedInfo{
|
||||
Subject: env.UserID,
|
||||
UserID: env.UserID,
|
||||
TeamID: env.TeamID,
|
||||
TenantID: env.TeamID,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou/application"
|
||||
)
|
||||
|
||||
// PathResolver resolves agent information from file paths
|
||||
|
|
@ -367,12 +368,22 @@ func CreateTestCaseFromMessage(message string) *Case {
|
|||
// ResolvePathWithYaoRoot resolves a file path relative to current directory
|
||||
// No fallback to YAO_ROOT - paths are always resolved from current working directory
|
||||
func ResolvePathWithYaoRoot(path string) string {
|
||||
// If path is absolute, return as-is
|
||||
if filepath.IsAbs(path) {
|
||||
return path
|
||||
}
|
||||
|
||||
// Resolve relative to current directory
|
||||
// Try resolving relative to the application root first
|
||||
if application.App != nil {
|
||||
appRoot := application.App.Root()
|
||||
if appRoot != "" {
|
||||
candidate := filepath.Join(appRoot, path)
|
||||
if _, err := os.Stat(candidate); err == nil {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: resolve relative to cwd
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return path
|
||||
|
|
|
|||
|
|
@ -339,7 +339,8 @@ func NewEnvironmentWithContext(userID, teamID string, ctxConfig *ContextConfig)
|
|||
|
||||
// LoadContextConfig loads context configuration from a JSON file
|
||||
func LoadContextConfig(filePath string) (*ContextConfig, error) {
|
||||
data, err := os.ReadFile(filePath)
|
||||
resolvedPath := ResolvePathWithYaoRoot(filePath)
|
||||
data, err := os.ReadFile(resolvedPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read context file: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue