Files
hanzoai_agent/control-plane/internal/templates/templates.go
zeekay 2899aeaa9f feat: merge agents control plane + SDKs into unified agent repo
Consolidate all Hanzo agent infrastructure into one repo:
- control-plane/: Go control plane server (was agents-new)
- sdk/: Go, Python, TypeScript SDKs
- deployments/: Docker, Kubernetes, Helm configs
- Dockerfile.sdk: Python SDK image (ghcr.io/hanzoai/agent:latest)
- CI builds both SDK + control-plane images

No more agentfield — everything is hanzoai/agent.
2026-02-13 12:24:31 -08:00

77 lines
2.2 KiB
Go

package templates
import (
"embed"
"fmt"
"io/fs"
"strings"
"text/template"
)
//go:embed python/*.tmpl go/*.tmpl typescript/*.tmpl
var content embed.FS
// TemplateData holds the data to be passed to the templates.
type TemplateData struct {
ProjectName string // "my-awesome-agent"
NodeID string // "my-awesome-agent" (same as ProjectName)
GoModule string // "my-awesome-agent" (Go module name)
AuthorName string // "John Doe"
AuthorEmail string // "[email protected]"
CurrentYear int // 2025
CreatedAt string // "2025-01-05 10:30:00 EST"
Language string // "python", "go", or "typescript"
}
// GetTemplate retrieves a specific template by its path.
func GetTemplate(name string) (*template.Template, error) {
tmpl, err := template.ParseFS(content, name)
if err != nil {
return nil, err
}
return tmpl, nil
}
// GetTemplateFiles returns a map of template file paths for the specified language.
// The map keys are the template paths in the embed.FS, and values are the destination paths.
func GetTemplateFiles(language string) (map[string]string, error) {
files := make(map[string]string)
// Determine the language directory
langDir := language
if language != "python" && language != "go" && language != "typescript" {
return nil, fmt.Errorf("unsupported language: %s (supported: python, go, typescript)", language)
}
// Walk the language-specific directory
err := fs.WalkDir(content, langDir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() && strings.HasSuffix(path, ".tmpl") {
// Remove the language prefix and .tmpl suffix
// e.g., "python/main.py.tmpl" -> "main.py"
relativePath := strings.TrimPrefix(path, langDir+"/")
relativePath = strings.TrimSuffix(relativePath, ".tmpl")
files[path] = relativePath
}
return nil
})
if err != nil {
return nil, err
}
return files, nil
}
// ReadTemplateContent reads the content of an embedded template file.
func ReadTemplateContent(path string) ([]byte, error) {
return content.ReadFile(path)
}
// GetSupportedLanguages returns the list of supported languages.
func GetSupportedLanguages() []string {
return []string{"python", "go", "typescript"}
}