Merge pull request #1471 from trheyi/main
Enhance context handling in tool calls and improve path resolution
This commit is contained in:
commit
701082bb9c
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
|
// Call tool (pass ctx as extraArgs for Process transport to propagate Authorized())
|
||||||
result, err := client.CallTool(ctx.Context, name, arguments)
|
result, err := client.CallTool(ctx.Context, name, arguments, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if node != nil {
|
if node != nil {
|
||||||
node.Fail(err)
|
node.Fail(err)
|
||||||
|
|
@ -273,8 +273,8 @@ func (ctx *Context) CallTools(mcpID string, tools []types.ToolCall) (*types.Call
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call tools sequentially
|
// Call tools sequentially (pass ctx as extraArgs for Process transport to propagate Authorized())
|
||||||
result, err := client.CallTools(ctx.Context, tools)
|
result, err := client.CallTools(ctx.Context, tools, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if node != nil {
|
if node != nil {
|
||||||
node.Fail(err)
|
node.Fail(err)
|
||||||
|
|
@ -328,8 +328,8 @@ func (ctx *Context) CallToolsParallel(mcpID string, tools []types.ToolCall) (*ty
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call tools in parallel
|
// Call tools in parallel (pass ctx as extraArgs for Process transport to propagate Authorized())
|
||||||
result, err := client.CallToolsParallel(ctx.Context, tools)
|
result, err := client.CallToolsParallel(ctx.Context, tools, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if node != nil {
|
if node != nil {
|
||||||
node.Fail(err)
|
node.Fail(err)
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ func buildAuthorizedInfo(env *Environment) *types.AuthorizedInfo {
|
||||||
authorized := &types.AuthorizedInfo{
|
authorized := &types.AuthorizedInfo{
|
||||||
Subject: env.UserID,
|
Subject: env.UserID,
|
||||||
UserID: env.UserID,
|
UserID: env.UserID,
|
||||||
|
TeamID: env.TeamID,
|
||||||
TenantID: env.TeamID,
|
TenantID: env.TeamID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"github.com/yaoapp/gou/application"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PathResolver resolves agent information from file paths
|
// 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
|
// ResolvePathWithYaoRoot resolves a file path relative to current directory
|
||||||
// No fallback to YAO_ROOT - paths are always resolved from current working directory
|
// No fallback to YAO_ROOT - paths are always resolved from current working directory
|
||||||
func ResolvePathWithYaoRoot(path string) string {
|
func ResolvePathWithYaoRoot(path string) string {
|
||||||
// If path is absolute, return as-is
|
|
||||||
if filepath.IsAbs(path) {
|
if filepath.IsAbs(path) {
|
||||||
return 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)
|
absPath, err := filepath.Abs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return path
|
return path
|
||||||
|
|
|
||||||
|
|
@ -339,7 +339,8 @@ func NewEnvironmentWithContext(userID, teamID string, ctxConfig *ContextConfig)
|
||||||
|
|
||||||
// LoadContextConfig loads context configuration from a JSON file
|
// LoadContextConfig loads context configuration from a JSON file
|
||||||
func LoadContextConfig(filePath string) (*ContextConfig, error) {
|
func LoadContextConfig(filePath string) (*ContextConfig, error) {
|
||||||
data, err := os.ReadFile(filePath)
|
resolvedPath := ResolvePathWithYaoRoot(filePath)
|
||||||
|
data, err := os.ReadFile(resolvedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read context file: %w", err)
|
return nil, fmt.Errorf("failed to read context file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue