Documentation
¶
Index ¶
- func ComponentPrompt(spec ComponentSpec) string
- func ContextEnrichedPrompt(spec ComponentSpec, availableModules []string, availableServices []string) string
- func DynamicComponentPrompt(spec ComponentSpec) string
- func ExamplePromptSection(examples map[string]string) string
- func GeneratePrompt(req GenerateRequest) string
- func LoadExampleConfigs(exampleDir string) (map[string]string, error)
- func MissingComponentsPrompt(moduleTypes []string) string
- func SuggestPrompt(useCase string) string
- func SystemPrompt() string
- type ComponentFormat
- type ComponentSpec
- type DeployHandler
- type DeployService
- type GenerateRequest
- type GenerateResponse
- type Handler
- func (h *Handler) HandleComponent(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleGenerate(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleProviders(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleSuggest(w http.ResponseWriter, r *http.Request)
- func (h *Handler) RegisterRoutes(mux *http.ServeMux)
- type Provider
- type Service
- func (s *Service) ClearCache()
- func (s *Service) GenerateComponent(ctx context.Context, spec ComponentSpec) (string, error)
- func (s *Service) GenerateWorkflow(ctx context.Context, req GenerateRequest) (*GenerateResponse, error)
- func (s *Service) IdentifyMissingComponents(ctx context.Context, cfg *config.WorkflowConfig) ([]ComponentSpec, error)
- func (s *Service) Providers() []Provider
- func (s *Service) RegisterGenerator(provider Provider, gen WorkflowGenerator)
- func (s *Service) SetPreferred(provider Provider)
- func (s *Service) SuggestWorkflow(ctx context.Context, useCase string) ([]WorkflowSuggestion, error)
- type ValidationConfig
- type ValidationResult
- type Validator
- func (v *Validator) BuildFixPrompt(spec ComponentSpec, source string, errors []string) string
- func (v *Validator) ValidateAndFix(ctx context.Context, aiService *Service, spec ComponentSpec, source string) (string, *ValidationResult, error)
- func (v *Validator) ValidateSource(source string) *ValidationResult
- type WorkflowGenerator
- type WorkflowSuggestion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComponentPrompt ¶
func ComponentPrompt(spec ComponentSpec) string
ComponentPrompt builds a prompt for generating a single component.
func ContextEnrichedPrompt ¶
func ContextEnrichedPrompt(spec ComponentSpec, availableModules []string, availableServices []string) string
ContextEnrichedPrompt enriches a component generation prompt with available module types and services so the AI can generate components that integrate with the existing system.
func DynamicComponentPrompt ¶
func DynamicComponentPrompt(spec ComponentSpec) string
DynamicComponentPrompt builds a prompt for generating a component in dynamic format. Dynamic components are flat packages with exported functions that can be loaded by the Yaegi interpreter at runtime.
func ExamplePromptSection ¶
ExamplePromptSection builds a prompt section with example configs.
func GeneratePrompt ¶
func GeneratePrompt(req GenerateRequest) string
GeneratePrompt builds a workflow generation prompt from the request.
func LoadExampleConfigs ¶
LoadExampleConfigs reads example YAML files from the given directory and returns them as a map of filename to content.
func MissingComponentsPrompt ¶
MissingComponentsPrompt builds a prompt for identifying missing components.
func SuggestPrompt ¶
SuggestPrompt builds a prompt for workflow suggestions.
func SystemPrompt ¶
func SystemPrompt() string
SystemPrompt returns the system prompt describing the workflow engine capabilities.
Types ¶
type ComponentFormat ¶
type ComponentFormat string
ComponentFormat specifies the target format for generated component code.
const ( // FormatModule generates code implementing the modular.Module interface (struct-based). FormatModule ComponentFormat = "module" // FormatDynamic generates code as a flat package with exported functions // compatible with the Yaegi dynamic interpreter. FormatDynamic ComponentFormat = "dynamic" )
type ComponentSpec ¶
type ComponentSpec struct {
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description"`
Interface string `json:"interface"` // e.g., "modular.Module", "MessageHandler"
GoCode string `json:"goCode"` // Generated Go source
}
ComponentSpec describes a workflow component that may need to be created.
type DeployHandler ¶
type DeployHandler struct {
// contains filtered or unexported fields
}
DeployHandler provides HTTP handlers for the AI deploy API.
func NewDeployHandler ¶
func NewDeployHandler(deploy *DeployService) *DeployHandler
NewDeployHandler creates a new deploy API handler.
func (*DeployHandler) HandleDeploy ¶
func (h *DeployHandler) HandleDeploy(w http.ResponseWriter, r *http.Request)
HandleDeploy handles POST /api/ai/deploy. It takes an intent string, generates the workflow and components, deploys components to the dynamic registry, and returns the result.
func (*DeployHandler) HandleDeployComponent ¶
func (h *DeployHandler) HandleDeployComponent(w http.ResponseWriter, r *http.Request)
HandleDeployComponent handles POST /api/ai/deploy/component. It deploys a single component to the dynamic registry.
func (*DeployHandler) RegisterRoutes ¶
func (h *DeployHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers the deploy API routes on a ServeMux.
type DeployService ¶
type DeployService struct {
// contains filtered or unexported fields
}
DeployService bridges AI code generation with the dynamic component system. It generates components in dynamic format and loads them into the Yaegi interpreter at runtime.
func NewDeployService ¶
func NewDeployService(ai *Service, registry *dynamic.ComponentRegistry, pool *dynamic.InterpreterPool) *DeployService
NewDeployService creates a DeployService that connects the AI service to the dynamic component registry.
func (*DeployService) DeployComponent ¶
func (d *DeployService) DeployComponent(ctx context.Context, spec ComponentSpec) error
DeployComponent takes a ComponentSpec, generates dynamic-format code if needed, validates it, and loads it into the dynamic component registry.
func (*DeployService) GenerateAndDeploy ¶
func (d *DeployService) GenerateAndDeploy(ctx context.Context, intent string) (*config.WorkflowConfig, error)
GenerateAndDeploy takes a natural language intent, generates the workflow config and any required components, loads the components into the dynamic registry, and returns the config.
func (*DeployService) SaveConfig ¶
func (d *DeployService) SaveConfig(cfg *config.WorkflowConfig, path string) error
SaveConfig writes a WorkflowConfig to a YAML file.
type GenerateRequest ¶
type GenerateRequest struct {
Intent string `json:"intent"` // Natural language description
Context map[string]string `json:"context"` // Additional context
Constraints []string `json:"constraints"` // Requirements/constraints
}
GenerateRequest contains the input for workflow generation.
type GenerateResponse ¶
type GenerateResponse struct {
Workflow *config.WorkflowConfig `json:"workflow"`
Components []ComponentSpec `json:"components"`
Explanation string `json:"explanation"`
}
GenerateResponse contains the output of workflow generation.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides HTTP handlers for the AI service API.
func NewHandler ¶
NewHandler creates a new AI API handler.
func (*Handler) HandleComponent ¶
func (h *Handler) HandleComponent(w http.ResponseWriter, r *http.Request)
HandleComponent handles POST /api/ai/component
func (*Handler) HandleGenerate ¶
func (h *Handler) HandleGenerate(w http.ResponseWriter, r *http.Request)
HandleGenerate handles POST /api/ai/generate
func (*Handler) HandleProviders ¶
func (h *Handler) HandleProviders(w http.ResponseWriter, r *http.Request)
HandleProviders handles GET /api/ai/providers
func (*Handler) HandleSuggest ¶
func (h *Handler) HandleSuggest(w http.ResponseWriter, r *http.Request)
HandleSuggest handles POST /api/ai/suggest
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers the AI API routes on a ServeMux.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service coordinates multiple AI generator backends with provider selection, caching, and rate limiting.
func (*Service) GenerateComponent ¶
GenerateComponent generates Go source code for a component.
func (*Service) GenerateWorkflow ¶
func (s *Service) GenerateWorkflow(ctx context.Context, req GenerateRequest) (*GenerateResponse, error)
GenerateWorkflow creates a workflow config from a natural language request.
func (*Service) IdentifyMissingComponents ¶
func (s *Service) IdentifyMissingComponents(ctx context.Context, cfg *config.WorkflowConfig) ([]ComponentSpec, error)
IdentifyMissingComponents analyzes a config for non-built-in module types.
func (*Service) RegisterGenerator ¶
func (s *Service) RegisterGenerator(provider Provider, gen WorkflowGenerator)
RegisterGenerator registers an AI generator for a provider.
func (*Service) SetPreferred ¶
SetPreferred sets the preferred provider. Use ProviderAuto to auto-select.
func (*Service) SuggestWorkflow ¶
func (s *Service) SuggestWorkflow(ctx context.Context, useCase string) ([]WorkflowSuggestion, error)
SuggestWorkflow returns cached or fresh suggestions for a use case.
type ValidationConfig ¶
type ValidationConfig struct {
MaxRetries int `json:"maxRetries"`
CompileCheck bool `json:"compileCheck"`
RequiredFuncCheck bool `json:"requiredFuncCheck"`
}
ValidationConfig configures the validation loop behavior.
func DefaultValidationConfig ¶
func DefaultValidationConfig() ValidationConfig
DefaultValidationConfig returns sensible defaults.
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
Errors []string `json:"errors,omitempty"`
Warnings []string `json:"warnings,omitempty"`
}
ValidationResult holds the outcome of source code validation.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates and optionally fixes AI-generated component source code.
func NewValidator ¶
func NewValidator(config ValidationConfig, pool *dynamic.InterpreterPool) *Validator
NewValidator creates a Validator with the given config and interpreter pool.
func (*Validator) BuildFixPrompt ¶
func (v *Validator) BuildFixPrompt(spec ComponentSpec, source string, errors []string) string
BuildFixPrompt formats a prompt that includes the original spec, the failing source code, and the list of errors so the AI can produce a corrected version.
func (*Validator) ValidateAndFix ¶
func (v *Validator) ValidateAndFix(ctx context.Context, aiService *Service, spec ComponentSpec, source string) (string, *ValidationResult, error)
ValidateAndFix runs a validation loop that attempts to fix invalid source code by asking the AI service to regenerate with error context. It returns the final source, validation result, and any error encountered.
func (*Validator) ValidateSource ¶
func (v *Validator) ValidateSource(source string) *ValidationResult
ValidateSource checks the given source code for correctness. It validates imports, optionally compiles with Yaegi, and checks for required exported functions.
type WorkflowGenerator ¶
type WorkflowGenerator interface {
// GenerateWorkflow creates a complete workflow config from a natural language request.
GenerateWorkflow(ctx context.Context, req GenerateRequest) (*GenerateResponse, error)
// GenerateComponent generates Go source code for a component specification.
GenerateComponent(ctx context.Context, spec ComponentSpec) (string, error)
// SuggestWorkflow returns workflow suggestions for a given use case description.
SuggestWorkflow(ctx context.Context, useCase string) ([]WorkflowSuggestion, error)
// IdentifyMissingComponents analyzes a workflow config and returns specs for
// components that need to be created.
IdentifyMissingComponents(ctx context.Context, cfg *config.WorkflowConfig) ([]ComponentSpec, error)
}
WorkflowGenerator defines the interface for AI-powered workflow generation. Implementations include direct LLM clients and Copilot SDK wrappers.
type WorkflowSuggestion ¶
type WorkflowSuggestion struct {
Name string `json:"name"`
Description string `json:"description"`
Config *config.WorkflowConfig `json:"config"`
Confidence float64 `json:"confidence"`
}
WorkflowSuggestion represents a suggested workflow with confidence score.