serve

package
v1.3.104 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const PlaceholderAuthToken = "sk-change-me-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

PlaceholderAuthToken is the API token written by `mothx serve init-config`. It is a well-known value, so leaving it in place is equivalent to publishing the API key: the server warns on startup until it is replaced.

View Source
const PlaceholderAuthTokenWarning = "WARNING: serve.json ships the placeholder API token (" + PlaceholderAuthToken + "),\n" +
	"         which is public. Replace api.auth.tokens before enabling auth or exposing this server."

PlaceholderAuthTokenWarning is printed wherever a template token is created or is still in use.

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath() string

func DecodeConfigBytesInto

func DecodeConfigBytesInto(cfg *Config, data []byte) error

func InitConfig

func InitConfig(force bool) (string, error)

func InitConfigForProject

func InitConfigForProject(project bool, force bool) (string, error)

func IsPlaceholderAuthToken

func IsPlaceholderAuthToken(token string) bool

IsPlaceholderAuthToken reports whether token is the generated template value.

func ProjectConfigPath

func ProjectConfigPath() string

func Run

func Run(opts RunOptions, version string) error

func SaveConfig

func SaveConfig(path string, cfg *Config) error

func UsesPlaceholderAuthToken

func UsesPlaceholderAuthToken(cfg *Config) bool

UsesPlaceholderAuthToken reports whether the resolved config enables auth and still ships the generated template token, which means the API is reachable with a publicly known key.

Types

type ChannelConfig

type ChannelConfig struct {
	Artifact bool                  `json:"artifact,omitempty"`
	Wechat   channels.WechatConfig `json:"wechat"`
	Feishu   channels.FeishuConfig `json:"feishu"`
}

type Config

type Config struct {
	API         openaiapi.Config        `json:"api"`
	Features    FeatureConfig           `json:"features"`
	Channels    ChannelConfig           `json:"channels"`
	WebUI       WebUIConfig             `json:"webUI"`
	LobsterMode bool                    `json:"lobsterMode,omitempty"`
	Cron        channels.CronConfig     `json:"cron"`
	Memory      channels.MemoryConfig   `json:"memory"`
	Security    channels.SecurityConfig `json:"security"`
	Hooks       channels.HooksConfig    `json:"hooks"`
	Agent       channels.AgentConfig    `json:"agent"`
}

func DecodeConfigBytes

func DecodeConfigBytes(data []byte) (*Config, error)

func DefaultConfig

func DefaultConfig() *Config

func LoadConfig

func LoadConfig() (*Config, error)

func LoadConfigFrom

func LoadConfigFrom(path string) (*Config, error)

func (*Config) MarshalJSON

func (c *Config) MarshalJSON() ([]byte, error)

type ConfigLayer

type ConfigLayer string
const (
	ConfigLayerGlobal   ConfigLayer = "global"
	ConfigLayerProject  ConfigLayer = "project"
	ConfigLayerExplicit ConfigLayer = "explicit"
)

type FeatureConfig

type FeatureConfig struct {
	WebUI      bool `json:"webUI,omitempty"`
	OpenAIAPI  bool `json:"openaiAPI,omitempty"`
	Wechat     bool `json:"wechat,omitempty"`
	Feishu     bool `json:"feishu,omitempty"`
	MultiAgent bool `json:"multiAgent,omitempty"`
	Cron       bool `json:"cron,omitempty"`
	Memory     bool `json:"memory,omitempty"`
}

type PlatformSupervisor

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

PlatformSupervisor is the sole owner of live messaging platform instances. Callers receive snapshots and never retain the internal map or slice.

func NewPlatformSupervisor

func NewPlatformSupervisor() *PlatformSupervisor

func (*PlatformSupervisor) Get

func (*PlatformSupervisor) RemoveIf

func (s *PlatformSupervisor) RemoveIf(name string, platform messaging.Platform) bool

RemoveIf removes platform only when it is still the registered instance. This prevents a late Start return from deleting a newer replacement.

func (*PlatformSupervisor) Replace

func (s *PlatformSupervisor) Replace(name string, platform messaging.Platform) messaging.Platform

func (*PlatformSupervisor) ReplaceIf

func (s *PlatformSupervisor) ReplaceIf(name string, expected, platform messaging.Platform) bool

ReplaceIf swaps an instance only when expected is still the owner. It is used by asynchronous candidate startup so a late result cannot overwrite a newer configuration update.

func (*PlatformSupervisor) Snapshot

func (s *PlatformSupervisor) Snapshot() []messaging.Platform

func (*PlatformSupervisor) StopAll

func (s *PlatformSupervisor) StopAll() error

type RunOptions

type RunOptions struct {
	ConfigPath string
	Port       string
	WebUIDir   string
	Provider   string
	Model      string
	WorkDir    string
	Unsafe     bool
	Sandbox    bool
	MultiAgent bool
	Delegate   bool
	Workflows  bool
	WebSearch  bool
	Browser    bool
	Artifact   bool
	A2AMaster  bool
	Lobster    bool
	Verbose    bool
	Debug      bool
	// OnReady observes the fully constructed API server and channel dispatcher.
	OnReady func(*openaiapi.Server, *channels.Dispatcher)
	// Shutdown requests graceful termination of the nested API runtime.
	Shutdown <-chan struct{}
}

type ServeConfigState

type ServeConfigState struct {
	Effective     *Config
	WritablePath  string
	WritableLayer ConfigLayer
	// contains filtered or unexported fields
}

ServeConfigState separates the merged runtime configuration from the file layer edited by the WebUI. Runtime CLI overrides are never written back.

func (*ServeConfigState) Reload

func (s *ServeConfigState) Reload() error

func (*ServeConfigState) Snapshot

func (s *ServeConfigState) Snapshot() *Config

Snapshot returns an isolated runtime configuration snapshot. Callers may safely pass it to code that normalizes or annotates the configuration.

func (*ServeConfigState) UpdateChannel

func (s *ServeConfigState) UpdateChannel(platform string, body []byte, apply func(*Config) error) (channelConfigPatchResponse, error)

UpdateChannel applies a channel merge-patch to the selected writable layer, applies the resulting effective runtime config, and restores the old file if runtime application fails. The callback must not perform network I/O.

func (*ServeConfigState) UpdateFull

func (s *ServeConfigState) UpdateFull(body []byte, apply func(*Config) error) (*Config, error)

UpdateFull persists a complete serve configuration through the same serialize/apply/rollback boundary as channel updates. The body is decoded into a normalized writable-layer representation; CLI runtime overrides stay effective in memory but are stripped from the persisted copy.

type SessionLifecycleService

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

SessionLifecycleService is the single coordinator for session persistence, API pool state and dispatcher cache state. Database helpers remain in the session package; this service owns the cross-runtime lock and ordering.

func NewSessionLifecycleService

func NewSessionLifecycleService(sessions interface{ DeleteActiveSession(string) (bool, error) }, dispatcher *channels.Dispatcher, sessionDir string, identityMux *session.IdentityLocks) *SessionLifecycleService

func (*SessionLifecycleService) Bind

func (s *SessionLifecycleService) Bind(ctx context.Context, sessionID, channelType, channelID string) error

func (*SessionLifecycleService) Delete

func (s *SessionLifecycleService) Delete(ctx context.Context, sessionID string) (bool, error)

func (*SessionLifecycleService) Rotate

func (s *SessionLifecycleService) Rotate(ctx context.Context, platform, userID string, force bool) error

Rotate creates a new bound session for a channel identity. It is used by the channel /new and /clear commands so those commands share the same runtime/identity lock ordering as HTTP binding mutations. A forced rotate requests cancellation of the active run and waits a bounded grace period; it never rotates without a durable mutation lease.

func (*SessionLifecycleService) SetEventPublisher

func (s *SessionLifecycleService) SetEventPublisher(publish func(string, any))

func (*SessionLifecycleService) Transfer

func (s *SessionLifecycleService) Transfer(ctx context.Context, channelType, channelID, fromSessionID, toSessionID string) error

func (*SessionLifecycleService) Unbind

func (s *SessionLifecycleService) Unbind(ctx context.Context, sessionID string) (*session.Binding, error)

type WebUIConfig

type WebUIConfig struct {
	Enabled bool   `json:"enabled"`
	Dir     string `json:"dir,omitempty"`
}

Directories

Path Synopsis
Package hooks implements shell hook scripts for serve channels.
Package hooks implements shell hook scripts for serve channels.

Jump to

Keyboard shortcuts

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