返回 DeepSeek-Reasonix
contextual.go
根目录 / internal / tool / contextual.go
1 package tool
2
3 import (
4 "context"
5 "fmt"
6 "strings"
7 )
8
9 // ContextualAvailabilityReason optionally explains a failed ContextualTool
10 // check. Implementations must be observational and return no private data.
11 type ContextualAvailabilityReason interface {
12 UnavailableReason(context.Context) string
13 }
14
15 // ContextualUnavailableReason is shared by discovery and the execution gate.
16 // It does not change registry membership or provider-visible tool schemas.
17 func ContextualUnavailableReason(ctx context.Context, target Tool) string {
18 contextual, ok := target.(ContextualTool)
19 if !ok || contextual.ProviderVisible(ctx) {
20 return ""
21 }
22 if diagnostic, ok := target.(ContextualAvailabilityReason); ok {
23 if reason := strings.TrimSpace(diagnostic.UnavailableReason(ctx)); reason != "" {
24 return strings.TrimPrefix(reason, "blocked: ")
25 }
26 }
27 return fmt.Sprintf("tool %q is unavailable in the current workflow context", target.Name())
28 }
29
29 lines GO