mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package agent
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
func resolveAgentToolAllowlist(definition AgentContextDefinition) []string {
|
|
if frontmatterParseFailed(definition) {
|
|
return []string{}
|
|
}
|
|
if definition.Agent == nil || definition.Agent.Frontmatter.Tools == nil {
|
|
return nil
|
|
}
|
|
|
|
allowlist := make(map[string]struct{}, len(definition.Agent.Frontmatter.Tools))
|
|
for _, raw := range definition.Agent.Frontmatter.Tools {
|
|
trimmed := strings.ToLower(strings.TrimSpace(raw))
|
|
if trimmed == "" {
|
|
continue
|
|
}
|
|
allowlist[trimmed] = struct{}{}
|
|
}
|
|
|
|
result := make([]string, 0, len(allowlist))
|
|
for name := range allowlist {
|
|
result = append(result, name)
|
|
}
|
|
sort.Strings(result)
|
|
return result
|
|
}
|
|
|
|
func resolveAgentMCPServerAllowlist(definition AgentContextDefinition) map[string]struct{} {
|
|
if frontmatterParseFailed(definition) {
|
|
return map[string]struct{}{}
|
|
}
|
|
if definition.Agent == nil || definition.Agent.Frontmatter.MCPServers == nil {
|
|
return nil
|
|
}
|
|
|
|
allowlist := make(map[string]struct{}, len(definition.Agent.Frontmatter.MCPServers))
|
|
for _, raw := range definition.Agent.Frontmatter.MCPServers {
|
|
trimmed := strings.ToLower(strings.TrimSpace(raw))
|
|
if trimmed == "" {
|
|
continue
|
|
}
|
|
allowlist[trimmed] = struct{}{}
|
|
}
|
|
|
|
return allowlist
|
|
}
|
|
|
|
func frontmatterParseFailed(definition AgentContextDefinition) bool {
|
|
if definition.Agent == nil {
|
|
return false
|
|
}
|
|
if strings.TrimSpace(definition.Agent.RawFrontmatter) == "" {
|
|
return false
|
|
}
|
|
return strings.TrimSpace(definition.Agent.FrontmatterErr) != ""
|
|
}
|