appsdk

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeUnprocessableEntity = 1
	CodeBadRequest          = 2
	CodeNotFound            = 3
	CodeUnauthorized        = 4
	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 New

func New(options Options) *App

func (*App) AutoRegisterTargets

func (a *App) AutoRegisterTargets() []ExtensionRegistration

func (*App) DeclareExtension

func (a *App) DeclareExtension(name string, systemVersion string) error

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) HasMethod

func (a *App) HasMethod(method string) bool

func (*App) Methods

func (a *App) Methods() []string

func (*App) Options

func (a *App) Options() Options

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

func (*App) Use

func (a *App) Use(extension Extension) error

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 Channel

type Channel struct {
	ID string `json:"id"`
}

type Chat

type Chat struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

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 (c Context) GetAuthToken() string

func (*Context) UnmarshalJSON

func (c *Context) UnmarshalJSON(data []byte) error

type ErrorMapper

type ErrorMapper func(error) error

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 Extension

type Extension interface {
	Register(app *App) error
}

type ExtensionRegistration

type ExtensionRegistration struct {
	Name          string `json:"name"`
	SystemVersion string `json:"systemVersion"`
}

type ExtraFields

type ExtraFields map[string]any

type FunctionError

type FunctionError struct {
	Code    int
	Type    string
	Message string
	Data    any
}

func NewError

func NewError(code int, typ string, message string, data ...any) *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 FunctionSchema struct {
	Name         string         `json:"name"`
	Description  string         `json:"description,omitempty"`
	InputSchema  map[string]any `json:"inputSchema"`
	OutputSchema map[string]any `json:"outputSchema,omitempty"`
}

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 InputHandlerFunc[TIn any] func(ctx context.Context, fnCtx Context, input *TIn) (any, error)

type Options

type Options struct {
	AppID       string
	AppSecret   string
	Debug       bool
	ErrorMapper ErrorMapper
}

type ResultMarshaler

type ResultMarshaler interface {
	MarshalSDKResult() (json.RawMessage, error)
}

type TypedHandlerFunc

type TypedHandlerFunc[TIn any, TOut any] func(ctx context.Context, fnCtx Context, input *TIn) (*TOut, error)

type User

type User struct {
	ID        string          `json:"id,omitempty"`
	ChannelID string          `json:"channelId,omitempty"`
	Type      string          `json:"type,omitempty"`
	Member    bool            `json:"member,omitempty"`
	MemberID  string          `json:"memberId,omitempty"`
	Profile   json.RawMessage `json:"profile,omitempty"`
}

type UserChat

type UserChat struct {
	ID      string          `json:"id,omitempty"`
	Profile json.RawMessage `json:"profile,omitempty"`
	State   string          `json:"state,omitempty"`
}

type Validator

type Validator interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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