50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
|
|
"ollie/paths"
|
|
)
|
|
|
|
// defaultPromptsDir returns the default directory for prompt templates.
|
|
func defaultPromptsDir() string {
|
|
return paths.CfgDir() + "/prompts"
|
|
}
|
|
|
|
// PromptsDirs returns all prompt directories. Currently just the default.
|
|
func PromptsDirs() []string {
|
|
return []string{defaultPromptsDir()}
|
|
}
|
|
|
|
// AgentsDirs returns all agent directories. Currently just the default.
|
|
func AgentsDirs() []string {
|
|
return []string{paths.CfgDir() + "/agents"}
|
|
}
|
|
|
|
// AgentConfigPath resolves the config file path for a named agent.
|
|
func AgentConfigPath(agentsDir, name string) string {
|
|
for _, dir := range AgentsDirs() {
|
|
p := dir + "/" + name + ".json"
|
|
if _, err := os.Stat(p); err == nil {
|
|
return p
|
|
}
|
|
}
|
|
return agentsDir + "/" + name + ".json"
|
|
}
|
|
|
|
// LoadConfig loads an agent configuration file by profile name.
|
|
// If open is nil, os.Open is used.
|
|
func LoadConfig(agentsDir, name string, open func(string) (*os.File, error)) *AgentConfig {
|
|
if open == nil {
|
|
open = os.Open
|
|
}
|
|
path := AgentConfigPath(agentsDir, name)
|
|
f, err := open(path)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
defer f.Close()
|
|
cfg, _ := Load(f)
|
|
return cfg
|
|
}
|