processor

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package processor provides implementations for different response processors

Package processor provides response processing functionality for CronAI.

Package processor provides functionality for processing model responses through various output channels

Index

Constants

View Source
const (
	// Slack processor environment variables
	EnvSlackToken = "SLACK_TOKEN"

	// Email processor environment variables
	EnvSMTPServer   = "SMTP_SERVER"
	EnvSMTPPort     = "SMTP_PORT"
	EnvSMTPUser     = "SMTP_USER"
	EnvSMTPPassword = "SMTP_PASSWORD"
	EnvSMTPFrom     = "SMTP_FROM"

	// Webhook processor environment variables
	EnvWebhookURL     = "WEBHOOK_URL"
	EnvWebhookMethod  = "WEBHOOK_METHOD"
	EnvWebhookHeaders = "WEBHOOK_HEADERS"

	// Dynamic webhook environment variables (use with strings.ToUpper)
	EnvWebhookURLPrefix     = "WEBHOOK_URL_"
	EnvWebhookMethodPrefix  = "WEBHOOK_METHOD_"
	EnvWebhookHeadersPrefix = "WEBHOOK_HEADERS_"

	// File processor environment variables
	EnvLogsDirectory = "LOGS_DIRECTORY"

	// GitHub processor environment variables
	EnvGitHubToken = "GITHUB_TOKEN"

	// Default values
	DefaultSMTPPort      = "587"
	DefaultWebhookMethod = "POST"
	DefaultLogsDirectory = "logs"
)

Environment variable names for processors

Variables

This section is empty.

Functions

func FormatGitHubMessage

func FormatGitHubMessage(messageType string, data template.Data) string

FormatGitHubMessage formats a message for GitHub (issue, PR, comment) with a consistent structure This avoids duplication of formatting logic across different GitHub operations

func GetEnvWithDefault

func GetEnvWithDefault(key, defaultValue string) string

GetEnvWithDefault returns the value of the environment variable or a default value

func GetProcessorFunc

func GetProcessorFunc(config Config) func() (Processor, error)

GetProcessorFunc returns a function that creates a processor

func GetWebhookHeaders

func GetWebhookHeaders(webhookType string) string

GetWebhookHeaders returns the webhook headers for a specific type or the default

func GetWebhookMethod

func GetWebhookMethod(webhookType string) string

GetWebhookMethod returns the webhook method for a specific type or the default

func GetWebhookURL

func GetWebhookURL(webhookType string) string

GetWebhookURL returns the webhook URL for a specific type or the default

func InitTemplates

func InitTemplates(templateDir string) error

InitTemplates initializes the template system

func ProcessResponse

func ProcessResponse(processorName string, response *models.ModelResponse, templateName string) error

ProcessResponse processes a model response using the specified processor

func SetLogger

func SetLogger(l *logger.Logger)

SetLogger sets the logger for the processor package

Types

type Config

type Config struct {
	// Type identifies the processor type (email, slack, webhook, file, etc.)
	Type string `json:"type"`

	// Target specifies the destination (email address, webhook URL, file path, etc.)
	Target string `json:"target"`

	// Options contains processor-specific configuration
	Options map[string]interface{} `json:"options,omitempty"`

	// TemplateName specifies the template to use (optional)
	TemplateName string `json:"template_name,omitempty"`

	// Environment contains environment variable names used by the processor
	Environment map[string]string `json:"environment,omitempty"`
}

Config represents standardized configuration for processors

type ConsoleProcessor

type ConsoleProcessor struct {
	// contains filtered or unexported fields
}

ConsoleProcessor handles console output

func (*ConsoleProcessor) GetConfig

func (c *ConsoleProcessor) GetConfig() Config

GetConfig returns the processor configuration

func (*ConsoleProcessor) GetType

func (c *ConsoleProcessor) GetType() string

GetType returns the processor type identifier

func (*ConsoleProcessor) Process

func (c *ConsoleProcessor) Process(response *models.ModelResponse, templateName string) error

Process handles the model response with optional template

func (*ConsoleProcessor) Validate

func (c *ConsoleProcessor) Validate() error

Validate checks if the processor is properly configured

type EmailProcessor

type EmailProcessor struct {
	// contains filtered or unexported fields
}

EmailProcessor handles email processing

func (*EmailProcessor) GetConfig

func (e *EmailProcessor) GetConfig() Config

GetConfig returns the processor configuration

func (*EmailProcessor) GetType

func (e *EmailProcessor) GetType() string

GetType returns the processor type identifier

func (*EmailProcessor) Process

func (e *EmailProcessor) Process(response *models.ModelResponse, templateName string) error

Process handles the model response with optional template

func (*EmailProcessor) Validate

func (e *EmailProcessor) Validate() error

Validate checks if the processor is properly configured

type Factory

type Factory func(config Config) (Processor, error)

Factory is a function type that creates a new processor

type FileProcessor

type FileProcessor struct {
	// contains filtered or unexported fields
}

FileProcessor handles file output

func (*FileProcessor) GetConfig

func (f *FileProcessor) GetConfig() Config

GetConfig returns the processor configuration

func (*FileProcessor) GetType

func (f *FileProcessor) GetType() string

GetType returns the processor type identifier

func (*FileProcessor) Process

func (f *FileProcessor) Process(response *models.ModelResponse, templateName string) error

Process handles the model response with optional template

func (*FileProcessor) Validate

func (f *FileProcessor) Validate() error

Validate checks if the processor is properly configured

type GitHubProcessor

type GitHubProcessor struct {
	// contains filtered or unexported fields
}

GitHubProcessor handles GitHub operations (issues, comments, pull requests)

func (*GitHubProcessor) GetConfig

func (g *GitHubProcessor) GetConfig() Config

GetConfig returns the processor configuration

func (*GitHubProcessor) GetType

func (g *GitHubProcessor) GetType() string

GetType returns the processor type identifier

func (*GitHubProcessor) Process

func (g *GitHubProcessor) Process(response *models.ModelResponse, templateName string) error

Process handles the model response with optional template

func (*GitHubProcessor) Validate

func (g *GitHubProcessor) Validate() error

Validate checks if the processor is properly configured

type Options

type Options struct {
	TemplateDir string // Directory containing custom templates
}

Options contains options for processors

type Processor

type Processor interface {
	// Process handles the model response with optional template
	Process(response *models.ModelResponse, templateName string) error

	// Validate checks if the processor is properly configured
	Validate() error

	// GetType returns the processor type identifier
	GetType() string

	// GetConfig returns the processor configuration
	GetConfig() Config
}

Processor defines the interface for all response processors

func CreateProcessor

func CreateProcessor(processorType string, config Config) (Processor, error)

CreateProcessor creates a new processor using the global registry

func GetProcessor

func GetProcessor(config Config) (Processor, error)

GetProcessor creates a processor from the given config

func NewConsoleProcessor

func NewConsoleProcessor(config Config) (Processor, error)

NewConsoleProcessor creates a new console processor

func NewEmailProcessor

func NewEmailProcessor(config Config) (Processor, error)

NewEmailProcessor creates a new email processor

func NewFileProcessor

func NewFileProcessor(config Config) (Processor, error)

NewFileProcessor creates a new file processor

func NewGitHubProcessor

func NewGitHubProcessor(config Config) (Processor, error)

NewGitHubProcessor creates a new GitHub processor

func NewSlackProcessor

func NewSlackProcessor(config Config) (Processor, error)

NewSlackProcessor creates a new Slack processor

func NewWebhookProcessor

func NewWebhookProcessor(config Config) (Processor, error)

NewWebhookProcessor creates a new webhook processor

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages available processors

func GetRegistry

func GetRegistry() *Registry

GetRegistry returns the singleton registry instance

func (*Registry) CreateProcessor

func (r *Registry) CreateProcessor(processorType string, config Config) (Processor, error)

CreateProcessor creates a new processor instance

func (*Registry) GetProcessorTypes

func (r *Registry) GetProcessorTypes() []string

GetProcessorTypes returns all registered processor types

func (*Registry) RegisterDefaults

func (r *Registry) RegisterDefaults()

RegisterDefaults registers all default processors

func (*Registry) RegisterFactory

func (r *Registry) RegisterFactory(processorType string, factory Factory)

RegisterFactory registers a new processor factory

func (*Registry) RegisterProcessor

func (r *Registry) RegisterProcessor(processorType string, factory Factory)

RegisterProcessor registers a new processor factory

type SlackProcessor

type SlackProcessor struct {
	// contains filtered or unexported fields
}

SlackProcessor handles Slack messaging

func (*SlackProcessor) GetConfig

func (s *SlackProcessor) GetConfig() Config

GetConfig returns the processor configuration

func (*SlackProcessor) GetType

func (s *SlackProcessor) GetType() string

GetType returns the processor type identifier

func (*SlackProcessor) Process

func (s *SlackProcessor) Process(response *models.ModelResponse, templateName string) error

Process handles the model response with optional template

func (*SlackProcessor) Validate

func (s *SlackProcessor) Validate() error

Validate checks if the processor is properly configured

type WebhookProcessor

type WebhookProcessor struct {
	// contains filtered or unexported fields
}

WebhookProcessor handles webhook requests

func (*WebhookProcessor) GetConfig

func (w *WebhookProcessor) GetConfig() Config

GetConfig returns the processor configuration

func (*WebhookProcessor) GetType

func (w *WebhookProcessor) GetType() string

GetType returns the processor type identifier

func (*WebhookProcessor) Process

func (w *WebhookProcessor) Process(response *models.ModelResponse, templateName string) error

Process handles the model response with optional template

func (*WebhookProcessor) Validate

func (w *WebhookProcessor) Validate() error

Validate checks if the processor is properly configured

Directories

Path Synopsis
Package template provides template functions and management for CronAI.
Package template provides template functions and management for CronAI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL