Documentation
¶
Index ¶
- Constants
- func MustRegister[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...)
- func MustRegisterInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption)
- func MustRegisterProto[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...)
- func MustRegisterProtoInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption)
- func MustRegisterProtoTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...)
- func MustRegisterTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...)
- func Register[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...) error
- func RegisterInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption) error
- func RegisterProto[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...) error
- func RegisterProtoInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption) error
- func RegisterProtoTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...) error
- func RegisterTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], ...) error
- type App
- func (a *App) AutoRegisterTargets() []ExtensionRegistration
- func (a *App) DeclareExtension(name string, systemVersion string) error
- func (a *App) Extensions() []ExtensionRegistration
- func (a *App) Func(name string, opts ...FunctionOption)
- func (a *App) GetFunctions() FunctionResponse
- func (a *App) GetTestFunctions() FunctionResponse
- func (a *App) HandleJSON(ctx context.Context, body []byte) FunctionResponse
- func (a *App) HandleRequest(ctx context.Context, req FunctionRequest) FunctionResponse
- func (a *App) HasMethod(method string) bool
- func (a *App) Methods() []string
- func (a *App) Options() Options
- func (a *App) RegisterFunc(name string, opts ...FunctionOption) error
- func (a *App) RegisterTestFunc(name string, opts ...FunctionOption) error
- func (a *App) Schemas() []FunctionSchema
- func (a *App) TestFunc(name string, opts ...FunctionOption)
- func (a *App) TestSchemas() []FunctionSchema
- func (a *App) Use(extension Extension) error
- type Caller
- type CallerType
- type Channel
- type Chat
- type Context
- type ErrorMapper
- type Extensible
- type Extension
- type ExtensionRegistration
- type ExtraFields
- type FunctionError
- type FunctionErrorResponse
- type FunctionOption
- func Description(description string) FunctionOption
- func ExtensibleOutput[T any](fields ...schema.PropertySpec) FunctionOption
- func Handle[TIn any, TOut any](handler TypedHandlerFunc[TIn, TOut]) FunctionOption
- func HandleInput[TIn any](handler InputHandlerFunc[TIn]) FunctionOption
- func HandleProto[TIn any, TOut any](handler TypedHandlerFunc[TIn, TOut]) FunctionOption
- func HandleProtoInput[TIn any](handler InputHandlerFunc[TIn]) FunctionOption
- func Hidden() FunctionOption
- func Input[T any]() FunctionOption
- func InputSchema(input map[string]any) FunctionOption
- func MapErrors(mapper ErrorMapper) FunctionOption
- func Output[T any]() FunctionOption
- func OutputSchema(output map[string]any) FunctionOption
- func PatchInputSchema(patches ...schema.Patch) FunctionOption
- func PatchOutputSchema(patches ...schema.Patch) FunctionOption
- func ProtoHandler[TIn any, TOut any](handler TypedHandlerFunc[TIn, TOut]) []FunctionOption
- func RawHandler(handler HandlerFunc) FunctionOption
- func TestOnly() FunctionOption
- type FunctionRequest
- type FunctionResponse
- type FunctionSchema
- type GetFunctionsResponse
- type GetFunctionsResult
- type HandlerFunc
- type InputHandlerFunc
- type Options
- type ResultMarshaler
- type TypedHandlerFunc
- type User
- type UserChat
- type Validator
Constants ¶
View Source
const ( CodeUnprocessableEntity = 1 CodeBadRequest = 2 CodeNotFound = 3 CodeMethodNotFound = -32601 CodeInternal = -32603 )
View Source
const ( MethodGetFunctions = "extension.core.function.getFunctions" MethodGetTestFunctions = "extension.core.function.getTestFunctions" CoreExtensionName = "core" DefaultSystemVersion = "v1" )
Variables ¶
This section is empty.
Functions ¶
func MustRegister ¶
func MustRegister[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption)
func MustRegisterInput ¶
func MustRegisterInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption)
func MustRegisterProto ¶
func MustRegisterProto[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption)
func MustRegisterProtoInput ¶
func MustRegisterProtoInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption)
func MustRegisterProtoTest ¶
func MustRegisterProtoTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption)
func MustRegisterTest ¶
func MustRegisterTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption)
func Register ¶
func Register[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption) error
func RegisterInput ¶
func RegisterInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption) error
func RegisterProto ¶
func RegisterProto[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption) error
func RegisterProtoInput ¶
func RegisterProtoInput[TIn any](app *App, name string, handler InputHandlerFunc[TIn], opts ...FunctionOption) error
func RegisterProtoTest ¶
func RegisterProtoTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption) error
func RegisterTest ¶
func RegisterTest[TIn any, TOut any](app *App, name string, handler TypedHandlerFunc[TIn, TOut], opts ...FunctionOption) error
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) AutoRegisterTargets ¶
func (a *App) AutoRegisterTargets() []ExtensionRegistration
func (*App) DeclareExtension ¶
func (*App) Extensions ¶
func (a *App) Extensions() []ExtensionRegistration
func (*App) Func ¶
func (a *App) Func(name string, opts ...FunctionOption)
func (*App) GetFunctions ¶
func (a *App) GetFunctions() FunctionResponse
func (*App) GetTestFunctions ¶
func (a *App) GetTestFunctions() FunctionResponse
func (*App) HandleJSON ¶
func (a *App) HandleJSON(ctx context.Context, body []byte) FunctionResponse
func (*App) HandleRequest ¶
func (a *App) HandleRequest(ctx context.Context, req FunctionRequest) FunctionResponse
func (*App) RegisterFunc ¶
func (a *App) RegisterFunc(name string, opts ...FunctionOption) error
func (*App) RegisterTestFunc ¶
func (a *App) RegisterTestFunc(name string, opts ...FunctionOption) error
func (*App) Schemas ¶
func (a *App) Schemas() []FunctionSchema
func (*App) TestFunc ¶
func (a *App) TestFunc(name string, opts ...FunctionOption)
func (*App) TestSchemas ¶
func (a *App) TestSchemas() []FunctionSchema
type Caller ¶
type Caller struct {
Type CallerType `json:"type"`
ID string `json:"id,omitempty"`
}
type CallerType ¶
type CallerType string
const ( CallerTypeUser CallerType = "user" CallerTypeManager CallerType = "manager" CallerTypeSystem CallerType = "system" CallerTypeApp CallerType = "app" )
type Context ¶
type Context struct {
Caller Caller `json:"caller"`
Channel Channel `json:"channel"`
User *User `json:"user,omitempty"`
UserChat *UserChat `json:"userChat,omitempty"`
AuthToken string `json:"authToken,omitempty"`
LegacyAuthToken string `json:"legacyAuthToken,omitempty"`
APICredentials map[string]string `json:"apiCredentials,omitempty"`
Config map[string]any `json:"config,omitempty"`
Language string `json:"language,omitempty"`
Sandbox bool `json:"sandbox,omitempty"`
SessionID string `json:"sessionId,omitempty"`
SeedState any `json:"seedState,omitempty"`
}
func (Context) GetAuthToken ¶
func (*Context) UnmarshalJSON ¶
type ErrorMapper ¶
type Extensible ¶
type Extensible[T any] struct { Base *T Fields ExtraFields }
func WithExtraFields ¶
func WithExtraFields[T any](base *T, fields map[string]any) *Extensible[T]
func (*Extensible[T]) MarshalJSON ¶
func (e *Extensible[T]) MarshalJSON() ([]byte, error)
func (*Extensible[T]) MarshalSDKResult ¶
func (e *Extensible[T]) MarshalSDKResult() (json.RawMessage, error)
type ExtensionRegistration ¶
type ExtraFields ¶
type FunctionError ¶
func (*FunctionError) Error ¶
func (e *FunctionError) Error() string
type FunctionErrorResponse ¶
type FunctionErrorResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
// Type is an optional logical error category such as "invalidParams",
// "methodNotFound", or "internal". Keep code/message as the canonical contract.
Type string `json:"type,omitempty"`
}
type FunctionOption ¶
type FunctionOption func(*functionDefinition) error
func Description ¶
func Description(description string) FunctionOption
func ExtensibleOutput ¶
func ExtensibleOutput[T any](fields ...schema.PropertySpec) FunctionOption
func Handle ¶
func Handle[TIn any, TOut any](handler TypedHandlerFunc[TIn, TOut]) FunctionOption
func HandleInput ¶
func HandleInput[TIn any](handler InputHandlerFunc[TIn]) FunctionOption
func HandleProto ¶
func HandleProto[TIn any, TOut any](handler TypedHandlerFunc[TIn, TOut]) FunctionOption
func HandleProtoInput ¶
func HandleProtoInput[TIn any](handler InputHandlerFunc[TIn]) FunctionOption
func Hidden ¶
func Hidden() FunctionOption
func Input ¶
func Input[T any]() FunctionOption
func InputSchema ¶
func InputSchema(input map[string]any) FunctionOption
func MapErrors ¶
func MapErrors(mapper ErrorMapper) FunctionOption
func Output ¶
func Output[T any]() FunctionOption
func OutputSchema ¶
func OutputSchema(output map[string]any) FunctionOption
func PatchInputSchema ¶
func PatchInputSchema(patches ...schema.Patch) FunctionOption
func PatchOutputSchema ¶
func PatchOutputSchema(patches ...schema.Patch) FunctionOption
func ProtoHandler ¶
func ProtoHandler[TIn any, TOut any](handler TypedHandlerFunc[TIn, TOut]) []FunctionOption
func RawHandler ¶
func RawHandler(handler HandlerFunc) FunctionOption
func TestOnly ¶
func TestOnly() FunctionOption
type FunctionRequest ¶
type FunctionRequest struct {
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
Context Context `json:"context"`
SystemVersion string `json:"systemVersion,omitempty"`
}
type FunctionResponse ¶
type FunctionResponse struct {
Result json.RawMessage `json:"result,omitempty"`
Error *FunctionErrorResponse `json:"error,omitempty"`
}
func ErrorResponse ¶
func ErrorResponse(err error) FunctionResponse
func (FunctionResponse) IsError ¶
func (r FunctionResponse) IsError() bool
type FunctionSchema ¶
type GetFunctionsResponse ¶
type GetFunctionsResponse struct {
Result GetFunctionsResult `json:"result"`
}
type GetFunctionsResult ¶
type GetFunctionsResult struct {
Functions []FunctionSchema `json:"functions"`
Success bool `json:"success"`
ErrorMessage string `json:"errorMessage"`
}
type HandlerFunc ¶
type HandlerFunc func(ctx context.Context, fnCtx Context, params json.RawMessage) (json.RawMessage, error)
type InputHandlerFunc ¶
type Options ¶
type Options struct {
AppID string
AppSecret string
Debug bool
ErrorMapper ErrorMapper
}
type ResultMarshaler ¶
type ResultMarshaler interface {
MarshalSDKResult() (json.RawMessage, error)
}
type TypedHandlerFunc ¶
Click to show internal directories.
Click to hide internal directories.