bots

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BotTypePersonal = "personal"
	BotTypePublic   = "public"
)
View Source
const (
	BotStatusCreating = "creating"
	BotStatusReady    = "ready"
	BotStatusDeleting = "deleting"
)
View Source
const (
	BotCheckStateOK      = "ok"
	BotCheckStateIssue   = "issue"
	BotCheckStateUnknown = "unknown"
)
View Source
const (
	BotCheckStatusOK      = "ok"
	BotCheckStatusWarn    = "warn"
	BotCheckStatusError   = "error"
	BotCheckStatusUnknown = "unknown"
)
View Source
const (
	BotCheckTypeContainerInit   = "container.init"
	BotCheckTypeContainerRecord = "container.record"
	BotCheckTypeContainerTask   = "container.task"
	BotCheckTypeContainerData   = "container.data_path"
	BotCheckTypeDelete          = "bot.delete"
	BotCheckTypeMCPConnection   = "mcp.connection"
	BotCheckTypeChannelConn     = "channel.connection"
)
View Source
const (
	MemberRoleOwner  = "owner"
	MemberRoleAdmin  = "admin"
	MemberRoleMember = "member"
)

Variables

View Source
var (
	ErrBotNotFound       = errors.New("bot not found")
	ErrBotAccessDenied   = errors.New("bot access denied")
	ErrOwnerUserNotFound = errors.New("owner user not found")
)

Functions

This section is empty.

Types

type AccessPolicy

type AccessPolicy struct {
	AllowPublicMember bool
	AllowGuest        bool
}

AccessPolicy controls bot access behavior.

type Bot

type Bot struct {
	ID              string         `json:"id"`
	OwnerUserID     string         `json:"owner_user_id"`
	Type            string         `json:"type"`
	DisplayName     string         `json:"display_name"`
	AvatarURL       string         `json:"avatar_url,omitempty"`
	IsActive        bool           `json:"is_active"`
	AllowGuest      bool           `json:"allow_guest"`
	Status          string         `json:"status"`
	CheckState      string         `json:"check_state"`
	CheckIssueCount int32          `json:"check_issue_count"`
	Metadata        map[string]any `json:"metadata,omitempty"`
	CreatedAt       time.Time      `json:"created_at"`
	UpdatedAt       time.Time      `json:"updated_at"`
}

Bot represents a bot entity.

type BotCheck

type BotCheck struct {
	ID       string         `json:"id"`
	Type     string         `json:"type"`
	TitleKey string         `json:"title_key"`
	Subtitle string         `json:"subtitle,omitempty"`
	Status   string         `json:"status"`
	Summary  string         `json:"summary"`
	Detail   string         `json:"detail,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

BotCheck represents one resource check row for a bot.

type BotMember

type BotMember struct {
	BotID     string    `json:"bot_id"`
	UserID    string    `json:"user_id"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at"`
}

BotMember represents a bot membership record.

type ContainerLifecycle

type ContainerLifecycle interface {
	SetupBotContainer(ctx context.Context, botID string) error
	CleanupBotContainer(ctx context.Context, botID string) error
}

ContainerLifecycle handles container lifecycle events bound to bot operations.

type CreateBotRequest

type CreateBotRequest struct {
	Type        string         `json:"type"`
	DisplayName string         `json:"display_name,omitempty"`
	AvatarURL   string         `json:"avatar_url,omitempty"`
	IsActive    *bool          `json:"is_active,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

CreateBotRequest is the input for creating a bot.

type ListBotsResponse

type ListBotsResponse struct {
	Items []Bot `json:"items"`
}

ListBotsResponse wraps a list of bots.

type ListChecksResponse

type ListChecksResponse struct {
	Items []BotCheck `json:"items"`
}

ListChecksResponse wraps a list of bot checks.

type ListMembersResponse

type ListMembersResponse struct {
	Items []BotMember `json:"items"`
}

ListMembersResponse wraps a list of bot members.

type RuntimeChecker

type RuntimeChecker interface {
	// ListChecks evaluates dynamic runtime checks for a bot.
	ListChecks(ctx context.Context, botID string) []BotCheck
}

RuntimeChecker produces runtime check items for a bot.

type Service

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

Service provides bot CRUD and membership management.

func NewService

func NewService(log *slog.Logger, queries *sqlc.Queries) *Service

NewService creates a new bot service.

func (*Service) AddRuntimeChecker

func (s *Service) AddRuntimeChecker(c RuntimeChecker)

AddRuntimeChecker registers an additional runtime checker.

func (*Service) AuthorizeAccess

func (s *Service) AuthorizeAccess(ctx context.Context, userID, botID string, isAdmin bool, policy AccessPolicy) (Bot, error)

AuthorizeAccess checks whether userID may access the given bot.

func (*Service) Create

func (s *Service) Create(ctx context.Context, ownerUserID string, req CreateBotRequest) (Bot, error)

Create creates a new bot owned by owner user.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, botID string) error

Delete removes a bot and its associated resources.

func (*Service) DeleteMember

func (s *Service) DeleteMember(ctx context.Context, botID, channelIdentityID string) error

DeleteMember removes a member from a bot.

func (*Service) Get

func (s *Service) Get(ctx context.Context, botID string) (Bot, error)

Get returns a bot by its ID.

func (*Service) GetMember

func (s *Service) GetMember(ctx context.Context, botID, channelIdentityID string) (BotMember, error)

GetMember returns a specific bot member.

func (*Service) IsMember

func (s *Service) IsMember(ctx context.Context, botID, channelIdentityID string) (bool, error)

IsMember checks if a user is a member of a bot.

func (*Service) ListAccessible

func (s *Service) ListAccessible(ctx context.Context, channelIdentityID string) ([]Bot, error)

ListAccessible returns all bots the user can access (owned or member).

func (*Service) ListByMember

func (s *Service) ListByMember(ctx context.Context, channelIdentityID string) ([]Bot, error)

ListByMember returns bots where the user is a member.

func (*Service) ListByOwner

func (s *Service) ListByOwner(ctx context.Context, ownerUserID string) ([]Bot, error)

ListByOwner returns bots owned by the given user.

func (*Service) ListChecks

func (s *Service) ListChecks(ctx context.Context, botID string) ([]BotCheck, error)

ListChecks evaluates runtime resource checks for a bot.

func (*Service) ListMembers

func (s *Service) ListMembers(ctx context.Context, botID string) ([]BotMember, error)

ListMembers returns all members of a bot.

func (*Service) SetContainerLifecycle

func (s *Service) SetContainerLifecycle(lc ContainerLifecycle)

SetContainerLifecycle registers a container lifecycle handler for bot operations.

func (*Service) TransferOwner

func (s *Service) TransferOwner(ctx context.Context, botID string, ownerUserID string) (Bot, error)

TransferOwner transfers bot ownership to another user.

func (*Service) Update

func (s *Service) Update(ctx context.Context, botID string, req UpdateBotRequest) (Bot, error)

Update updates bot profile fields.

func (*Service) UpsertMember

func (s *Service) UpsertMember(ctx context.Context, botID string, req UpsertMemberRequest) (BotMember, error)

UpsertMember creates or updates a bot membership.

func (*Service) UpsertMemberSimple

func (s *Service) UpsertMemberSimple(ctx context.Context, botID, channelIdentityID, role string) error

UpsertMemberSimple creates or updates a bot membership with a direct channel identity ID and role. This satisfies the router.BotMemberService interface.

type TransferBotRequest

type TransferBotRequest struct {
	OwnerUserID string `json:"owner_user_id"`
}

TransferBotRequest is the input for transferring bot ownership.

type UpdateBotRequest

type UpdateBotRequest struct {
	DisplayName *string        `json:"display_name,omitempty"`
	AvatarURL   *string        `json:"avatar_url,omitempty"`
	IsActive    *bool          `json:"is_active,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

UpdateBotRequest is the input for updating a bot.

type UpsertMemberRequest

type UpsertMemberRequest struct {
	UserID string `json:"user_id"`
	Role   string `json:"role,omitempty"`
}

UpsertMemberRequest is the input for upserting a bot member.

Jump to

Keyboard shortcuts

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