Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultHTTPPingFunc(opts HTTPOptions) func(ctx context.Context) error
- func DefaultWSPingFunc(opts WSOptions) func(ctx context.Context) error
- type CallOpts
- type ChatRole
- type DefaultHandlerContext
- func (h *DefaultHandlerContext) Context() context.Context
- func (h *DefaultHandlerContext) Get(inputName string) any
- func (h *DefaultHandlerContext) GetBool(inputName string) (bool, bool)
- func (h *DefaultHandlerContext) GetFloat(inputName string) (float64, bool)
- func (h *DefaultHandlerContext) GetInput(name string) (Input, bool)
- func (h *DefaultHandlerContext) GetInt(inputName string) (int, bool)
- func (h *DefaultHandlerContext) GetOutput(name string) (Output, bool)
- func (h *DefaultHandlerContext) GetString(inputName string) (string, bool)
- func (h *DefaultHandlerContext) Inputs() map[string]Input
- func (h *DefaultHandlerContext) JSON(i any) error
- func (h *DefaultHandlerContext) Messages() Messages
- func (h *DefaultHandlerContext) Outputs() map[string]Output
- func (h *DefaultHandlerContext) Set(outputName string, value any)
- func (h *DefaultHandlerContext) SetMessages(messages Messages)
- type HTTPOptions
- type Handler
- type HandlerContext
- type HandlerContextOpts
- type HandlerFunc
- type IOType
- type Input
- type InputFilter
- type InputPublic
- type Messages
- type Method
- func (m *Method) AsPublic() MethodPublic
- func (m *Method) Call(inputData map[string]any, opts ...CallOpts) (*MethodResponse, error)
- func (m *Method) CallWithContext(ctx context.Context, inputData map[string]any, opts ...CallOpts) (*MethodResponse, error)
- func (m *Method) GetAudioInputs() []Input
- func (m *Method) GetFileInputs() []Input
- func (m *Method) GetImageInputs() []Input
- func (m *Method) GetInput(name string) (Input, bool)
- func (m *Method) GetInputs() []Input
- func (m *Method) GetInputsWithFilter(filter InputFilter) []Input
- func (m *Method) GetOutput(name string) (Output, bool)
- func (m *Method) GetOutputs() []Output
- func (m *Method) GetTextInputs() []Input
- func (m *Method) GetVideoInputs() []Input
- type MethodPublic
- type MethodResponse
- type Output
- type OutputPublic
- type Ping
- type PingFunc
- type Service
- func (s *Service) AddMethod(method *Method)
- func (s *Service) AsPublic() ServicePublic
- func (s *Service) CallMethod(ctx context.Context, methodName string, inputData map[string]any, ...) (*MethodResponse, error)
- func (s *Service) GetDefaultMethod() *Method
- func (s *Service) Ping(ctx context.Context) error
- type ServicePublic
- type WSOptions
Constants ¶
const ( ErrCodeServiceNotFound = 1 // "service not found" ErrCodeMethodNotFound = 2 // "method not found" )
Variables ¶
Functions ¶
func DefaultHTTPPingFunc ¶
func DefaultHTTPPingFunc(opts HTTPOptions) func(ctx context.Context) error
DefaultHTTPPingFunc returns a ping function for HTTP requests based on the provided options.
Types ¶
type DefaultHandlerContext ¶
type DefaultHandlerContext struct {
// contains filtered or unexported fields
}
DefaultHandlerContext is the default implementation of the HandlerContext interface.
func (*DefaultHandlerContext) Context ¶
func (h *DefaultHandlerContext) Context() context.Context
func (*DefaultHandlerContext) Get ¶
func (h *DefaultHandlerContext) Get(inputName string) any
func (*DefaultHandlerContext) GetBool ¶
func (h *DefaultHandlerContext) GetBool(inputName string) (bool, bool)
func (*DefaultHandlerContext) GetFloat ¶
func (h *DefaultHandlerContext) GetFloat(inputName string) (float64, bool)
func (*DefaultHandlerContext) GetInput ¶
func (h *DefaultHandlerContext) GetInput(name string) (Input, bool)
func (*DefaultHandlerContext) GetInt ¶
func (h *DefaultHandlerContext) GetInt(inputName string) (int, bool)
func (*DefaultHandlerContext) GetOutput ¶
func (h *DefaultHandlerContext) GetOutput(name string) (Output, bool)
func (*DefaultHandlerContext) GetString ¶
func (h *DefaultHandlerContext) GetString(inputName string) (string, bool)
func (*DefaultHandlerContext) Inputs ¶
func (h *DefaultHandlerContext) Inputs() map[string]Input
func (*DefaultHandlerContext) JSON ¶
func (h *DefaultHandlerContext) JSON(i any) error
JSON populates the outputs by marshaling the provided data to JSON and unmarshaling it into a map. If the input data is already a map, it is directly used to set outputs
func (*DefaultHandlerContext) Messages ¶
func (h *DefaultHandlerContext) Messages() Messages
func (*DefaultHandlerContext) Outputs ¶
func (h *DefaultHandlerContext) Outputs() map[string]Output
func (*DefaultHandlerContext) Set ¶
func (h *DefaultHandlerContext) Set(outputName string, value any)
func (*DefaultHandlerContext) SetMessages ¶
func (h *DefaultHandlerContext) SetMessages(messages Messages)
type HTTPOptions ¶
type HTTPOptions struct { Host string `json:"host,omitempty" yaml:"host,omitempty"` Port string `json:"port,omitempty" yaml:"port,omitempty"` Path string `json:"path,omitempty" yaml:"path,omitempty"` Method string `json:"method,omitempty" yaml:"method,omitempty"` Schema string `json:"schema,omitempty" yaml:"schema,omitempty"` }
HTTPOptions holds configuration options for HTTP requests.
type Handler ¶
type Handler struct { Name string `json:"name"` // Name is the name of the handler. Description map[string]string `json:"description,omitempty"` // Description is an optional description of the handler. Args map[string]any `json:"args"` // Args are the arguments for the handler. Do HandlerFunc `json:"-"` // Do is the handler function itself, which is not serialized to JSON. }
Handler represents a method handler with metadata, arguments, and the handler function itself.
type HandlerContext ¶
type HandlerContext interface { // Context returns the underlying context. Context() context.Context // Get retrieves the value of the specified input. Get(inputName string) any // GetString retrieves the string representation of the specified input. GetString(inputName string) (string, bool) // GetInt retrieves the integer representation of the specified input. GetInt(inputName string) (int, bool) // GetFloat retrieves the float representation of the specified input. GetFloat(inputName string) (float64, bool) // GetBool retrieves the boolean representation of the specified input. GetBool(inputName string) (bool, bool) // GetInput retrieves an Input by its name, if present. GetInput(name string) (Input, bool) // Inputs returns all input mappings. Inputs() map[string]Input // Set assigns a value to the specified output. Set(outputName string, value any) // GetOutput retrieves an Output by its name, if present. GetOutput(name string) (Output, bool) // Outputs returns all output mappings. Outputs() map[string]Output // JSON populates the outputs by marshaling and unmarshaling the provided data. JSON(data any) error // Messages returns all messages in the context. Messages() Messages // SetMessages sets the messages in the context. SetMessages(messages Messages) }
HandlerContext defines an interface for managing inputs and outputs and providing access to the underlying context.
func NewHandlerContext ¶
func NewHandlerContext(ctx context.Context, inputs map[string]Input, outputs map[string]Output, opts ...HandlerContextOpts) HandlerContext
NewHandlerContext creates a new DefaultHandlerContext with the provided context, inputs, and outputs.
type HandlerContextOpts ¶
type HandlerContextOpts func(handlerContext HandlerContext)
func WithMessages ¶
func WithMessages(messages Messages) HandlerContextOpts
WithMessages returns a HandlerContextOpts that sets the messages in the handler context.
type HandlerFunc ¶
type HandlerFunc func(ctx HandlerContext) error
HandlerFunc defines the function signature for method handlers, which receive a HandlerContext and return an error if something goes wrong.
type IOType ¶
type IOType string
IOType represents the type of input or output in a method (e.g., text, audio, image).
type Input ¶
type Input struct { Name string `json:"name" yaml:"name"` // Name of the input. Type IOType `json:"type" yaml:"type"` // Type of the input (e.g., text, audio, image, etc.). Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` // Optional description of the input. DefaultValue any `json:"default,omitempty" yaml:"default,omitempty"` // Optional default value for the input. IsRequired bool `json:"is_required" yaml:"is_required"` // Indicates if the input is required. // contains filtered or unexported fields }
Input represents the input data of a method.
func (*Input) AsPublic ¶
func (i *Input) AsPublic() InputPublic
type InputFilter ¶
InputFilter - filter for inputs. Returns true if the input should be included
type InputPublic ¶
type InputPublic struct { Name string `json:"name" yaml:"name"` // Name of the input. Type IOType `json:"type" yaml:"type"` // Type of the input (e.g., text, audio, image, etc.). Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` // Optional description of the input. DefaultValue any `json:"default,omitempty" yaml:"default,omitempty"` // Optional default value for the input. IsRequired bool `json:"is_required" yaml:"is_required"` // Indicates if the input is required. }
InputPublic represents the input data of a method.
type Method ¶
type Method struct { Name string `json:"name" yaml:"name"` Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` Inputs []Input `json:"inputs" yaml:"inputs"` Outputs []Output `json:"outputs" yaml:"outputs"` IsDefault bool `json:"is_default" yaml:"is_default"` Handler *Handler `json:"handler" yaml:"handler"` }
Method - describes the method of the service Contains the name, description, inputs and outputs. Also contains the name of the handler function and the handler itself
func (*Method) AsPublic ¶
func (m *Method) AsPublic() MethodPublic
func (*Method) Call ¶
Call - calls the method If the method has no handler, it returns an error Otherwise, it calls the handler It returns the result of the handler Preferably use CallWithContext
func (*Method) CallWithContext ¶
func (m *Method) CallWithContext(ctx context.Context, inputData map[string]any, opts ...CallOpts) (*MethodResponse, error)
CallWithContext - calls the method with the given context If the method has no handler, it returns an error Otherwise, it calls the handler It returns the result of the handler
func (*Method) GetAudioInputs ¶
GetAudioInputs - returns the list of audio inputs
func (*Method) GetFileInputs ¶
GetFileInputs - returns the list of file inputs
func (*Method) GetImageInputs ¶
GetImageInputs - returns the list of image inputs
func (*Method) GetInputsWithFilter ¶
func (m *Method) GetInputsWithFilter(filter InputFilter) []Input
GetInputsWithFilter - returns the list of inputs with the given filter.
func (*Method) GetOutputs ¶
GetOutputs - returns the list of outputs
func (*Method) GetTextInputs ¶
GetTextInputs - returns the list of text inputsq
func (*Method) GetVideoInputs ¶
GetVideoInputs - returns the list of video inputs
type MethodPublic ¶
type MethodPublic struct { Name string `json:"name" yaml:"name"` Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` Inputs []InputPublic `json:"inputs" yaml:"inputs"` Outputs []OutputPublic `json:"outputs" yaml:"outputs"` IsDefault bool `json:"is_default" yaml:"is_default"` }
MethodPublic - represents a method in the public API It can be used to print information about the method without sensitive data
type MethodResponse ¶
type MethodResponse struct { Outputs map[string]Output // Outputs contains the output data of the method. ServiceName string // ServiceName is the name of the service that the method belongs to. Err error // Err contains any error encountered during method execution. ErrCode int // ErrCode is the error code of the method. }
MethodResponse describes the response of a method, including output data and any errors.
type Output ¶
type Output struct { Name string `json:"name" yaml:"name"` // Name of the output. Type IOType `json:"type" yaml:"type"` // Type of the output (e.g., text, audio, image, etc.). Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` // Optional description of the output. DefaultValue any `json:"default,omitempty" yaml:"default,omitempty"` // Optional default value for the output. IsPrivate bool `json:"is_private" yaml:"is_private"` // Indicates if the output is private (for users). TODO: rename. // contains filtered or unexported fields }
Output represents the output data of a method.
func (*Output) AsPublic ¶
func (o *Output) AsPublic() OutputPublic
type OutputPublic ¶
type OutputPublic struct { Name string `json:"name" yaml:"name"` // Name of the output. Type IOType `json:"type" yaml:"type"` // Type of the output (e.g., text, audio, image, etc.). Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` // Optional description of the output. DefaultValue any `json:"default,omitempty" yaml:"default,omitempty"` // Optional default value for the output. IsPrivate bool `json:"is_private" yaml:"is_private"` // Indicates if the output is private (for users). TODO: rename. }
OutputPublic represents the output data of a method. It can be used to print information about the output without sensitive data
type Ping ¶
type Ping struct { // Name of the ping operation Name string `json:"name" yaml:"name"` // Args - Arguments for the ping operation, can vary by implementation Args map[string]any `json:"args,omitempty" yaml:"args,omitempty"` // contains filtered or unexported fields }
Ping represents a ping operation with its related data and function.
func NewHTTPPinger ¶
func NewHTTPPinger(opts HTTPOptions) *Ping
NewHTTPPinger creates a new Ping instance configured for HTTP pinging.
func NewWSPinger ¶
NewWSPinger creates a new Ping instance configured for WebSocket pinging.
type Service ¶
type Service struct { Name string `json:"name" yaml:"name"` Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` Methods map[string]*Method `json:"methods" yaml:"methods"` Pinger *Ping `json:"pinger,omitempty" yaml:"pinger,omitempty"` }
Service - describes the service of the application Contains the name, description and methods Can be used to call methods
func (*Service) AsPublic ¶
func (s *Service) AsPublic() ServicePublic
AsPublic - returns the service as a public service
func (*Service) CallMethod ¶
func (s *Service) CallMethod(ctx context.Context, methodName string, inputData map[string]any, opts ...CallOpts) (*MethodResponse, error)
CallMethod - calls the method with the given name If the method does not exist, it returns an error Otherwise, it calls the method and returns the result
func (*Service) GetDefaultMethod ¶
GetDefaultMethod - returns the method with the default flag If the service does not have a default method, it returns nil
type ServicePublic ¶
type ServicePublic struct { Name string `json:"name" yaml:"name"` Description map[string]string `json:"description,omitempty" yaml:"description,omitempty"` Methods map[string]MethodPublic `json:"methods" yaml:"methods"` }
ServicePublic - describes the service as public. It can be used to print information about the service without sensitive data
type WSOptions ¶
type WSOptions struct { Host string `json:"host,omitempty" yaml:"host,omitempty"` Port string `json:"port,omitempty" yaml:"port,omitempty"` Path string `json:"path,omitempty" yaml:"path,omitempty"` Schema string `json:"schema,omitempty" yaml:"schema,omitempty"` }
WSOptions holds configuration options for WebSocket