mirror of
https://github.com/anotherhadi/iknowyou.git
synced 2026-04-12 00:47:26 +02:00
init
This commit is contained in:
72
back/internal/tools/tools.go
Normal file
72
back/internal/tools/tools.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package tools
|
||||
|
||||
import "context"
|
||||
|
||||
type EventType string
|
||||
|
||||
const (
|
||||
EventTypeOutput EventType = "output" // raw ANSI text, payload is a plain string
|
||||
EventTypeError EventType = "error"
|
||||
EventTypeCount EventType = "count" // payload is int, additive — emit once or multiple times from Run
|
||||
EventTypeDone EventType = "done"
|
||||
)
|
||||
|
||||
type InputType string
|
||||
|
||||
const (
|
||||
InputTypeEmail InputType = "email"
|
||||
InputTypeUsername InputType = "username"
|
||||
InputTypePhone InputType = "phone"
|
||||
InputTypeIP InputType = "ip"
|
||||
InputTypeDomain InputType = "domain"
|
||||
InputTypePassword InputType = "password"
|
||||
InputTypeName InputType = "name"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Tool string `json:"tool"`
|
||||
Type EventType `json:"type"`
|
||||
Payload interface{} `json:"payload,omitempty"`
|
||||
}
|
||||
|
||||
// ToolRunner is the core interface every tool must implement.
|
||||
type ToolRunner interface {
|
||||
Name() string
|
||||
Description() string
|
||||
Link() string // URL to source or documentation
|
||||
Icon() string // Simple Icons slug, empty if none
|
||||
|
||||
InputTypes() []InputType
|
||||
|
||||
// Run executes the tool and sends Events to out. Must close out when done.
|
||||
// inputType indicates what kind of value target is (email, username, ...).
|
||||
Run(ctx context.Context, target string, inputType InputType, out chan<- Event) error
|
||||
}
|
||||
|
||||
type Configurable interface {
|
||||
ConfigPtr() interface{}
|
||||
}
|
||||
|
||||
type ConfigField struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // "string", "bool", "int", "float", "enum"
|
||||
Required bool `json:"required"`
|
||||
Default any `json:"default"`
|
||||
Description string `json:"description"`
|
||||
Value any `json:"value"`
|
||||
Options []string `json:"options,omitempty"` // non-empty when Type == "enum"
|
||||
}
|
||||
|
||||
type ConfigDescriber interface {
|
||||
ConfigFields() []ConfigField
|
||||
}
|
||||
|
||||
// AvailabilityChecker is implemented by tools that require an external binary.
|
||||
type AvailabilityChecker interface {
|
||||
Available() (ok bool, reason string)
|
||||
}
|
||||
|
||||
type DependencyLister interface {
|
||||
Dependencies() []string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user