Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultCacheDir() string
- func DefaultRepoConfigPath() string
- func FetchTemplate(entry *IndexEntry, cacheDir, indexPath, repoName string) (string, error)
- func GetRepoDirForType(repoType RepositoryType, repoName string) string
- func RenderDryRun(pkg *TemplatePackage, vars map[string]string, outDir string) error
- func SplitTemplateRef(ref string) (repo, name string)
- func ValidateChecksum(path, expected string) error
- type Docs
- type Examples
- type FileSpec
- type GenerationResult
- type Generator
- type Hook
- type HookSet
- type Index
- type IndexEntry
- type IndexSpec
- type Loader
- func (l *Loader) ListBuiltIn() ([]TemplateInfo, error)
- func (l *Loader) Load(name string) (*Template, error)
- func (l *Loader) LoadBuiltIn(name string) (*Template, error)
- func (l *Loader) LoadFromFile(path string) (*Template, error)
- func (l *Loader) LoadFromPath(path string) (*Template, error)
- func (l *Loader) LoadFromRegistry(ref string) (*Template, error)
- func (l *Loader) LoadFromRegistryWithRepo(ref string, repo Repository) (*Template, error)
- func (l *Loader) ReadTemplateFile(templateName, filePath string) ([]byte, error)
- type RepoConfig
- type RepoResolver
- type Repository
- type RepositoryType
- type Requirements
- type Template
- type TemplateConfig
- type TemplateFile
- type TemplateInfo
- type TemplateMetadata
- type TemplatePackage
- type TemplateRef
- type TemplateSource
- type TemplateSpec
- type Variable
- type VariableBinding
- type VariableBindingFilter
- type VariableBindingKind
Constants ¶
const (
// DefaultGitHubIndex points to the community templates repo index.
DefaultGitHubIndex = "https://raw.githubusercontent.com/AltairaLabs/promptkit-templates/main/index.yaml"
)
const (
// DefaultRepoName is the built-in shorthand for the community template repository.
DefaultRepoName = "community"
)
Variables ¶
var DefaultIndex = DefaultGitHubIndex
DefaultIndex is the index location used for remote loads (overridable in tests).
Functions ¶
func DefaultCacheDir ¶ added in v1.1.3
func DefaultCacheDir() string
DefaultCacheDir returns the default cache directory, preferring the user cache dir.
func DefaultRepoConfigPath ¶ added in v1.1.3
func DefaultRepoConfigPath() string
DefaultRepoConfigPath returns the default config file location for template repos.
func FetchTemplate ¶ added in v1.1.3
func FetchTemplate(entry *IndexEntry, cacheDir, indexPath, repoName string) (string, error)
FetchTemplate copies the template source into cacheDir/<name>/<version>/template.yaml. indexPath is used to resolve relative source paths.
func GetRepoDirForType ¶ added in v1.1.4
func GetRepoDirForType(repoType RepositoryType, repoName string) string
GetRepoDirForType returns a repo name suitable for use in cache paths. For unknown repos, returns a sanitized version of the URL/path.
func RenderDryRun ¶ added in v1.1.3
func RenderDryRun(pkg *TemplatePackage, vars map[string]string, outDir string) error
RenderDryRun renders the package with vars and writes to outDir.
func SplitTemplateRef ¶ added in v1.1.4
SplitTemplateRef is a standalone utility that splits "repo/template" into parts. Returns empty repo string if no repo prefix is present.
func ValidateChecksum ¶ added in v1.1.3
ValidateChecksum compares file sha256 to expected hex checksum (if provided).
Types ¶
type Docs ¶
type Docs struct {
GettingStarted string `yaml:"getting_started,omitempty" json:"getting_started,omitempty"`
APIReference string `yaml:"api_reference,omitempty" json:"api_reference,omitempty"`
Examples string `yaml:"examples,omitempty" json:"examples,omitempty"`
}
Docs contains documentation links
type Examples ¶
type Examples struct {
Scenarios []string `yaml:"scenarios,omitempty" json:"scenarios,omitempty"`
Providers []string `yaml:"providers,omitempty" json:"providers,omitempty"`
UseCases []string `yaml:"use_cases,omitempty" json:"use_cases,omitempty"`
}
Examples contains example data for quick testing
type FileSpec ¶
type FileSpec struct {
Path string `yaml:"path" json:"path"`
Template string `yaml:"template,omitempty" json:"template,omitempty"`
Content string `yaml:"content,omitempty" json:"content,omitempty"`
// Source is an external file path relative to the template directory
Source string `yaml:"source,omitempty" json:"source,omitempty"`
Condition string `yaml:"condition,omitempty" json:"condition,omitempty"`
ForEach string `yaml:"foreach,omitempty" json:"foreach,omitempty"`
Variables map[string]string `yaml:"variables,omitempty" json:"variables,omitempty"`
Executable bool `yaml:"executable,omitempty" json:"executable,omitempty"`
}
FileSpec defines a file to be generated from the template
type GenerationResult ¶
type GenerationResult struct {
Success bool
ProjectPath string
FilesCreated []string
Errors []error
Warnings []string
Duration time.Duration
}
GenerationResult contains the result of template generation
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator handles template generation and file creation
func NewGenerator ¶
NewGenerator creates a new template generator
func (*Generator) Generate ¶
func (g *Generator) Generate(config *TemplateConfig) (*GenerationResult, error)
Generate generates a project from the template
type Hook ¶
type Hook struct {
Message string `yaml:"message,omitempty" json:"message,omitempty"`
Command string `yaml:"command" json:"command"`
Condition string `yaml:"condition,omitempty" json:"condition,omitempty"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
}
Hook defines a command to run during generation
type HookSet ¶
type HookSet struct {
PreCreate []Hook `yaml:"pre_create,omitempty" json:"pre_create,omitempty"`
PostCreate []Hook `yaml:"post_create,omitempty" json:"post_create,omitempty"`
}
HookSet defines pre and post generation hooks
type Index ¶ added in v1.1.3
type Index struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata map[string]string `yaml:"metadata,omitempty"`
Spec IndexSpec `yaml:"spec"`
}
Index lists available templates using K8s-style metadata/spec.
type IndexEntry ¶ added in v1.1.3
type IndexEntry struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Description string `yaml:"description,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Source string `yaml:"source"` // path or URL (file-only for now)
Checksum string `yaml:"checksum,omitempty"`
Providers []string `yaml:"providers,omitempty"`
Author string `yaml:"author,omitempty"`
}
IndexEntry describes a remote template.
type IndexSpec ¶ added in v1.1.3
type IndexSpec struct {
Entries []IndexEntry `yaml:"entries"`
}
IndexSpec holds template entries.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading templates from various sources
func NewLoaderWithRepo ¶ added in v1.1.4
func NewLoaderWithRepo(cacheDir string, repo Repository) *Loader
NewLoaderWithRepo creates a new template loader with a specific repository
func (*Loader) ListBuiltIn ¶
func (l *Loader) ListBuiltIn() ([]TemplateInfo, error)
ListBuiltIn returns a list of all built-in templates
func (*Loader) LoadBuiltIn ¶
LoadBuiltIn loads a built-in template
func (*Loader) LoadFromFile ¶
LoadFromFile loads a template from a file path
func (*Loader) LoadFromPath ¶ added in v1.1.4
LoadFromPath loads a template from a file path or directory path If path is a directory, it looks for template.yaml inside it
func (*Loader) LoadFromRegistry ¶ added in v1.1.3
LoadFromRegistry fetches a template using the default index and cache.
func (*Loader) LoadFromRegistryWithRepo ¶ added in v1.1.4
func (l *Loader) LoadFromRegistryWithRepo(ref string, repo Repository) (*Template, error)
LoadFromRegistryWithRepo fetches a template using a specific repository.
type RepoConfig ¶ added in v1.1.3
type RepoConfig struct {
Repos map[string]Repository `yaml:"repos"`
}
RepoConfig stores named template repositories.
func LoadRepoConfig ¶ added in v1.1.3
func LoadRepoConfig(path string) (*RepoConfig, error)
LoadRepoConfig reads repo config from disk. Missing files return defaults.
func (*RepoConfig) Add ¶ added in v1.1.3
func (cfg *RepoConfig) Add(name, url string)
Add inserts or updates a repo entry.
func (*RepoConfig) Remove ¶ added in v1.1.3
func (cfg *RepoConfig) Remove(name string)
Remove deletes a repo entry (default repo is re-added via ensureDefaults).
func (*RepoConfig) Save ¶ added in v1.1.3
func (cfg *RepoConfig) Save(path string) error
Save writes the repo config to disk, creating parent directories as needed.
type RepoResolver ¶ added in v1.1.4
type RepoResolver struct {
// contains filtered or unexported fields
}
RepoResolver handles repository resolution and template reference parsing.
func NewRepoResolver ¶ added in v1.1.4
func NewRepoResolver(config *RepoConfig) *RepoResolver
NewRepoResolver creates a new repository resolver with the given config.
func (*RepoResolver) GetCachePath ¶ added in v1.1.4
func (r *RepoResolver) GetCachePath(cacheDir string, ref *TemplateRef) string
GetCachePath returns the cache path for a template within a repository.
func (*RepoResolver) ParseTemplateRef ¶ added in v1.1.4
func (r *RepoResolver) ParseTemplateRef(ref, defaultRepo string) (*TemplateRef, error)
ParseTemplateRef parses a template reference like "local/template@version" or "template@version". If no repo prefix is present, uses the provided defaultRepo.
func (*RepoResolver) ResolveRepoForTemplate ¶ added in v1.1.4
func (r *RepoResolver) ResolveRepoForTemplate( templateName, defaultRepo string, ) (repo Repository, cleanName string)
ResolveRepoForTemplate determines which repository to use for a template reference. It checks if the template name has a repo prefix and uses that, otherwise uses defaultRepo.
type Repository ¶ added in v1.1.4
type Repository struct {
Type RepositoryType `yaml:"type"`
URL string `yaml:"url"`
}
Repository represents a template repository
func ResolveIndex ¶ added in v1.1.3
func ResolveIndex(nameOrPath string, cfg *RepoConfig) Repository
ResolveIndex returns the Repository for a short name or creates one from a raw path.
type RepositoryType ¶ added in v1.1.4
type RepositoryType string
RepositoryType defines the type of template repository
const ( // RepositoryTypeRemoteGit is a remote git repository (HTTP/HTTPS URL) RepositoryTypeRemoteGit RepositoryType = "remoteGit" // RepositoryTypeLocal is a local filesystem path RepositoryTypeLocal RepositoryType = "local" )
type Requirements ¶
type Requirements struct {
CLIVersion string `yaml:"cli_version,omitempty" json:"cli_version,omitempty"`
Tools []string `yaml:"tools,omitempty" json:"tools,omitempty"`
}
Requirements defines template requirements
type Template ¶
type Template struct {
APIVersion string `yaml:"apiVersion" json:"apiVersion"`
Kind string `yaml:"kind" json:"kind"`
Metadata TemplateMetadata `yaml:"metadata" json:"metadata"`
Spec TemplateSpec `yaml:"spec" json:"spec"`
BaseDir string `yaml:"-" json:"-"` // directory containing the template file (for source resolution)
BaseURL string `yaml:"-" json:"-"` // base URL for remote templates (for source resolution)
}
Template represents a project template configuration
type TemplateConfig ¶
type TemplateConfig struct {
ProjectName string
OutputDir string
Variables map[string]interface{}
Template *Template
Verbose bool // Enable detailed logging
}
TemplateConfig holds the configuration for template generation
type TemplateFile ¶ added in v1.1.3
type TemplateFile struct {
Path string `yaml:"path"`
Content string `yaml:"content"`
Source string `yaml:"source,omitempty"`
}
TemplateFile is a single file in a template package.
type TemplateInfo ¶
type TemplateInfo struct {
Name string
Version string
Description string
Author string
Tags []string
Source TemplateSource
Verified bool
Downloads int
Path string
}
TemplateInfo contains metadata about a template
type TemplateMetadata ¶
type TemplateMetadata struct {
Name string `yaml:"name" json:"name"`
Labels map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty" json:"annotations,omitempty"`
}
TemplateMetadata contains template identification and metadata
type TemplatePackage ¶ added in v1.1.3
type TemplatePackage struct {
Files []TemplateFile `yaml:"files"`
}
TemplatePackage holds files to render.
func LoadTemplatePackage ¶ added in v1.1.3
func LoadTemplatePackage(path string) (*TemplatePackage, error)
LoadTemplatePackage loads a template package from path.
type TemplateRef ¶ added in v1.1.4
type TemplateRef struct {
RepoName string // e.g., "local", "community"
TemplateName string // e.g., "iot-maintenance-demo"
Version string // e.g., "1.0.0" or empty
Repository Repository // The resolved repository
}
TemplateRef represents a parsed template reference.
type TemplateSource ¶
type TemplateSource int
TemplateSource represents where a template comes from
const ( SourceBuiltIn TemplateSource = iota SourceRemote SourceLocal )
type TemplateSpec ¶
type TemplateSpec struct {
Variables []Variable `yaml:"variables,omitempty" json:"variables,omitempty"`
Files []FileSpec `yaml:"files" json:"files"`
Hooks *HookSet `yaml:"hooks,omitempty" json:"hooks,omitempty"`
Examples *Examples `yaml:"examples,omitempty" json:"examples,omitempty"`
Docs *Docs `yaml:"docs,omitempty" json:"docs,omitempty"`
Requires *Requirements `yaml:"requires,omitempty" json:"requires,omitempty"`
}
TemplateSpec defines the template specification
type Variable ¶
type Variable struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Type string `yaml:"type,omitempty" json:"type,omitempty"` // string, number, boolean, array, select
Default interface{} `yaml:"default,omitempty" json:"default,omitempty"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
Validation string `yaml:"validation,omitempty" json:"validation,omitempty"` // regex pattern
Options []string `yaml:"options,omitempty" json:"options,omitempty"` // for select/array types
Prompt string `yaml:"prompt,omitempty" json:"prompt,omitempty"` // interactive prompt text
// Binding enables automatic population from system resources and type-safe UI selection.
// This allows templates to declare semantic meaning for variables beyond just their data type.
Binding *VariableBinding `yaml:"binding,omitempty" json:"binding,omitempty"`
}
Variable defines a template variable that can be customized
type VariableBinding ¶ added in v1.1.10
type VariableBinding struct {
// Kind specifies the type of resource to bind to.
Kind VariableBindingKind `yaml:"kind" json:"kind"`
// Field specifies which field of the resource to bind (e.g., "name", "model").
Field string `yaml:"field,omitempty" json:"field,omitempty"`
// AutoPopulate enables automatic population of this variable from the bound resource.
// When true, the variable may be auto-filled and optionally hidden from the wizard.
AutoPopulate bool `yaml:"autoPopulate,omitempty" json:"autoPopulate,omitempty"`
// Filter specifies criteria for filtering bound resources.
Filter *VariableBindingFilter `yaml:"filter,omitempty" json:"filter,omitempty"`
}
VariableBinding defines how a variable binds to system resources. This enables automatic population from system resources and type-safe UI selection.
type VariableBindingFilter ¶ added in v1.1.10
type VariableBindingFilter struct {
// Capability filters resources by capability (e.g., "chat", "embeddings").
Capability string `yaml:"capability,omitempty" json:"capability,omitempty"`
// Labels filters resources by label selectors.
Labels map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"`
}
VariableBindingFilter specifies criteria for filtering bound resources.
type VariableBindingKind ¶ added in v1.1.10
type VariableBindingKind string
VariableBindingKind defines the type of resource a variable binds to.
const ( // BindingKindProject binds to project metadata (name, description, tags). BindingKindProject VariableBindingKind = "project" // BindingKindProvider binds to provider/model selection. BindingKindProvider VariableBindingKind = "provider" // BindingKindWorkspace binds to current workspace (name, namespace). BindingKindWorkspace VariableBindingKind = "workspace" // BindingKindSecret binds to Kubernetes Secret resources. BindingKindSecret VariableBindingKind = "secret" // BindingKindConfigMap binds to Kubernetes ConfigMap resources. BindingKindConfigMap VariableBindingKind = "configmap" )