65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package toolsrv
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// MemoryTier implements MemoryTierClassifier. Looks up the tool's tier
|
|
// from the registry, then from its .meta file.
|
|
func (e *Server) MemoryTier(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"
|
|
}
|
|
|
|
// OutputFormat returns the source-fence language for a tool's output.
|
|
// Empty means the output should be wrapped in a plaintext fence.
|
|
func (e *Server) OutputFormat(name string) string {
|
|
if e.toolRegistry != nil && e.sessionID != "" {
|
|
if info, ok := e.toolRegistry.Lookup(e.sessionID, name); ok {
|
|
return info.OutputFormat
|
|
}
|
|
}
|
|
m, err := LoadMetaFile(name)
|
|
if err == nil && m != nil {
|
|
if resolved := m.Resolve(); resolved != nil {
|
|
return resolved.OutputFormat
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// MemoryTierArgs classifies the tier using both the outer tool name and its
|
|
// arguments. For shell, it returns warm. For promoted tools, it
|
|
// delegates to MemoryTier.
|
|
func (e *Server) MemoryTierArgs(name string, args json.RawMessage) string {
|
|
switch name {
|
|
case "shell":
|
|
return "warm"
|
|
default:
|
|
return e.MemoryTier(name)
|
|
}
|
|
}
|
|
|
|
// CanParallelize implements ParallelClassifier. Returns true when the
|
|
// named tool is marked readOnly in its .meta file.
|
|
func (e *Server) CanParallelize(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
|
|
}
|