ollie/toolsrv/tier.go

48 lines
1.2 KiB
Go

package toolsrv
import (
"encoding/json"
)
// ResultTier implements TierClassifier. Looks up the tool's tier
// from the registry, then from its .meta file.
func (e *Server) ResultTier(name string) string {
if e.toolRegistry != nil && e.sessionID != "" {
if info, ok := e.toolRegistry.Lookup(e.sessionID, name); ok && info.Tier != "" {
return info.Tier
}
}
m, err := LoadMetaFile(name)
if err == nil && m != nil && m.Tier != "" {
return m.Tier
}
return "hot"
}
// ResultTierArgs classifies the tier using both the outer tool name and its
// arguments. For shell, it returns warm. For promoted tools, it
// delegates to ResultTier.
func (e *Server) ResultTierArgs(name string, args json.RawMessage) string {
switch name {
case "shell":
return "warm"
default:
return e.ResultTier(name)
}
}
// IsParallelRead implements ParallelClassifier. Returns true when the
// named tool is marked readOnly in its .meta file.
func (e *Server) IsParallelRead(name string) bool {
if e.toolRegistry != nil && e.sessionID != "" {
if info, ok := e.toolRegistry.Lookup(e.sessionID, name); ok {
return info.ReadOnly
}
}
m, err := LoadMetaFile(name)
if err == nil && m != nil {
return m.ReadOnly
}
return false
}