formfiller

package
v0.0.0-...-8acab51 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package formfiller provides intelligent form filling capabilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDomain = errors.New("invalid site domain")

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled bool         `json:"enabled"`
	Widget  WidgetConfig `json:"widget"`
	// Password configuration is handled client-side for security
	Detection DetectionConfig `json:"detection"`
	Learning  LearningConfig  `json:"learning"`
}

Config represents the form filler configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

type CreateTemplateRequest

type CreateTemplateRequest struct {
	Name      string            `json:"name"`
	IsDefault bool              `json:"is_default"`
	Fields    map[string]string `json:"fields"`
}

CreateTemplateRequest represents a request to create a template.

type DetectRequest

type DetectRequest struct {
	HTML       string `json:"html"`
	URL        string `json:"url,omitempty"`
	TemplateID string `json:"template_id,omitempty"`
}

DetectRequest represents a field detection request.

type DetectResponse

type DetectResponse struct {
	Fields []DetectedField `json:"fields"`
	Count  int             `json:"count"`
}

DetectResponse represents a field detection response.

type DetectedField

type DetectedField struct {
	Selector        string          `json:"selector"`
	FieldType       FieldType       `json:"field_type"`
	Confidence      float64         `json:"confidence"`
	DetectionSource DetectionSource `json:"detection_source"`
	SuggestedValue  string          `json:"suggested_value,omitempty"`
	Attributes      FieldAttributes `json:"attributes"`
}

DetectedField represents a detected form field.

type DetectionConfig

type DetectionConfig struct {
	UseLLMFallback      bool    `json:"use_llm_fallback"`
	ConfidenceThreshold float64 `json:"confidence_threshold"`
	ScanIntervalMs      int     `json:"scan_interval_ms"`
}

DetectionConfig represents detection configuration.

type DetectionSource

type DetectionSource string

DetectionSource indicates how a field was detected.

const (
	DetectionAttribute DetectionSource = "attribute"
	DetectionLabel     DetectionSource = "label"
	DetectionPattern   DetectionSource = "pattern"
	DetectionLLM       DetectionSource = "llm"
)

type Detector

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

Detector handles field detection logic.

func NewDetector

func NewDetector(patterns *FieldPatterns) *Detector

NewDetector creates a new field detector.

func (*Detector) DetectFieldType

func (d *Detector) DetectFieldType(attrs FieldAttributes) (FieldType, float64, DetectionSource)

DetectFieldType detects the field type from attributes.

func (*Detector) DetectFields

func (d *Detector) DetectFields(fields []FieldAttributes, template *FillTemplate) []DetectedField

DetectFields detects fields from a list of field attributes.

type FieldAttributes

type FieldAttributes struct {
	ID           string `json:"id,omitempty"`
	Name         string `json:"name,omitempty"`
	Type         string `json:"type,omitempty"`
	Placeholder  string `json:"placeholder,omitempty"`
	Autocomplete string `json:"autocomplete,omitempty"`
	Label        string `json:"label,omitempty"`
}

FieldAttributes contains HTML attributes of a form field.

type FieldPatterns

type FieldPatterns struct {
	Patterns  map[FieldType][]string `json:"patterns"`
	UpdatedAt time.Time              `json:"updated_at"`
}

FieldPatterns represents field detection patterns.

func DefaultPatterns

func DefaultPatterns() *FieldPatterns

DefaultPatterns returns the default field detection patterns.

type FieldType

type FieldType string

FieldType represents the type of a form field.

const (
	FieldFirstName       FieldType = "firstName"
	FieldLastName        FieldType = "lastName"
	FieldFullName        FieldType = "fullName"
	FieldEmail           FieldType = "email"
	FieldPhone           FieldType = "phone"
	FieldAddress         FieldType = "address"
	FieldCity            FieldType = "city"
	FieldState           FieldType = "state"
	FieldZipCode         FieldType = "zipCode"
	FieldCountry         FieldType = "country"
	FieldUsername        FieldType = "username"
	FieldPassword        FieldType = "password"
	FieldConfirmPassword FieldType = "confirmPassword"
	FieldBirthDate       FieldType = "birthDate"
	FieldCompany         FieldType = "company"
	FieldTitle           FieldType = "title"
	FieldCustom          FieldType = "custom"
)

type FillTemplate

type FillTemplate struct {
	ID        string            `json:"id"`
	Name      string            `json:"name"`
	IsDefault bool              `json:"is_default"`
	Fields    map[string]string `json:"fields"`
	CreatedAt time.Time         `json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
}

FillTemplate represents a fill template with field values.

type Handler

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

Handler handles HTTP requests for form filler.

func NewHandler

func NewHandler(store *Store) *Handler

NewHandler creates a new form filler handler.

func NewLazyHandler

func NewLazyHandler(initFn func() (*Store, error)) *Handler

NewLazyHandler creates a handler whose store is initialized on first use.

func (*Handler) CreateTemplate

func (h *Handler) CreateTemplate(c echo.Context) error

CreateTemplate creates a new template.

func (*Handler) DeleteTemplate

func (h *Handler) DeleteTemplate(c echo.Context) error

DeleteTemplate deletes a template.

func (*Handler) DetectFields

func (h *Handler) DetectFields(c echo.Context) error

DetectFields detects fields from HTML or field attributes.

func (*Handler) GetConfig

func (h *Handler) GetConfig(c echo.Context) error

GetConfig returns the form filler configuration.

func (*Handler) GetPatterns

func (h *Handler) GetPatterns(c echo.Context) error

GetPatterns returns the field patterns.

func (*Handler) GetSiteMapping

func (h *Handler) GetSiteMapping(c echo.Context) error

GetSiteMapping returns a site mapping by domain.

func (*Handler) GetTemplate

func (h *Handler) GetTemplate(c echo.Context) error

GetTemplate returns a template by ID.

func (*Handler) ListTemplates

func (h *Handler) ListTemplates(c echo.Context) error

ListTemplates returns all templates.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(g *echo.Group)

RegisterRoutes registers the form filler routes.

func (*Handler) SaveSiteMapping

func (h *Handler) SaveSiteMapping(c echo.Context) error

SaveSiteMapping saves a site mapping.

func (*Handler) UpdatePatterns

func (h *Handler) UpdatePatterns(c echo.Context) error

UpdatePatterns updates the field patterns.

func (*Handler) UpdateTemplate

func (h *Handler) UpdateTemplate(c echo.Context) error

UpdateTemplate updates an existing template.

type LearningConfig

type LearningConfig struct {
	Enabled         bool `json:"enabled"`
	SyncEnabled     bool `json:"sync_enabled"`
	MaxSiteMappings int  `json:"max_site_mappings"`
}

LearningConfig represents learning configuration.

type SiteMapping

type SiteMapping struct {
	Domain          string            `json:"domain"`
	FieldMappings   map[string]string `json:"field_mappings"` // selector -> fieldType
	LastUsed        time.Time         `json:"last_used"`
	UserCorrections int               `json:"user_corrections"`
}

SiteMapping represents site-specific field mappings.

type Store

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

Store handles persistence for form filler data.

func NewStore

func NewStore(dataDir string) (*Store, error)

NewStore creates a new form filler store.

func (*Store) CreateTemplate

func (s *Store) CreateTemplate(req *CreateTemplateRequest) (*FillTemplate, error)

CreateTemplate creates a new template.

func (*Store) DeleteTemplate

func (s *Store) DeleteTemplate(id string) error

DeleteTemplate deletes a template.

func (*Store) GetDefaultTemplate

func (s *Store) GetDefaultTemplate() *FillTemplate

GetDefaultTemplate returns the default template.

func (*Store) GetPatterns

func (s *Store) GetPatterns() *FieldPatterns

GetPatterns returns the field patterns.

func (*Store) GetSiteMapping

func (s *Store) GetSiteMapping(domain string) (*SiteMapping, error)

GetSiteMapping returns a site mapping by domain.

func (*Store) GetTemplate

func (s *Store) GetTemplate(id string) (*FillTemplate, error)

GetTemplate returns a template by ID.

func (*Store) ListTemplates

func (s *Store) ListTemplates() []*FillTemplate

ListTemplates returns all templates.

func (*Store) SaveSiteMapping

func (s *Store) SaveSiteMapping(mapping *SiteMapping) error

SaveSiteMapping saves a site mapping.

func (*Store) UpdatePatterns

func (s *Store) UpdatePatterns(patterns map[FieldType][]string) error

UpdatePatterns updates the field patterns.

func (*Store) UpdateTemplate

func (s *Store) UpdateTemplate(id string, req *UpdateTemplateRequest) (*FillTemplate, error)

UpdateTemplate updates an existing template.

type UpdateTemplateRequest

type UpdateTemplateRequest struct {
	Name      string            `json:"name,omitempty"`
	IsDefault *bool             `json:"is_default,omitempty"`
	Fields    map[string]string `json:"fields,omitempty"`
}

UpdateTemplateRequest represents a request to update a template.

type WidgetConfig

type WidgetConfig struct {
	DefaultPosition  string `json:"default_position"`
	KeyboardShortcut string `json:"keyboard_shortcut"`
	AutoShowOnForms  bool   `json:"auto_show_on_forms"`
}

WidgetConfig represents widget configuration.

Jump to

Keyboard shortcuts

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