server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Overview

Package server provides the public PowerContext server configuration and lifecycle facade.

Index

Constants

View Source
const (
	PowerContextHomeEnv = "POWERCONTEXT_HOME"
	DefaultMCPPath      = "/mcp"
)

Variables

This section is empty.

Functions

func DefaultDatabasePath

func DefaultDatabasePath() (string, error)

func DefaultSchedulerPath

func DefaultSchedulerPath() (string, error)

func DefaultSeekDBPath

func DefaultSeekDBPath() (string, error)

func NewHTTPHandler

func NewHTTPHandler(handler v1.Handler, options HTTPOptions) (http.Handler, error)

NewHTTPHandler assembles the generated OpenAPI server and the transport-wide policy middleware. Lifecycle and listener ownership remain with cmd/server.

func PowerContextDataDir

func PowerContextDataDir() (string, error)

PowerContextDataDir matches platformdirs.user_data_path("powercontext", appauthor=False) on the supported Linux and macOS release targets.

func SQLiteDSN

func SQLiteDSN(value string) (string, error)

SQLiteDSN converts the frozen SQLAlchemy URL spelling without accepting a different database scheme by accident. Three-slash URLs intentionally keep a relative database path: the frozen .env.example relies on resolving that path from the Server working directory, just as SQLAlchemy does.

Types

type Application

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

Application is one fully assembled Runtime and its shared endpoint adapter. Close is idempotent and drains admitted work before closing persistence.

func OpenApplication

func OpenApplication(ctx context.Context, config ProcessConfig, dependencies Dependencies) (*Application, error)

OpenApplication initializes persistence projections before making any operation reachable. A partially initialized application is always closed.

func (*Application) Close

func (a *Application) Close(ctx context.Context) error

func (*Application) Endpoint

func (a *Application) Endpoint() v1.Handler

func (*Application) HTTPHandler

func (a *Application) HTTPHandler() (http.Handler, error)

type AuthConfig

type AuthConfig struct {
	Enabled bool
	Token   string `json:"-"`
}

func (AuthConfig) GoString

func (c AuthConfig) GoString() string

func (AuthConfig) LogValue

func (c AuthConfig) LogValue() slog.Value

func (AuthConfig) String

func (c AuthConfig) String() string

type AuthenticationTokenRequiredError

type AuthenticationTokenRequiredError struct{}

AuthenticationTokenRequiredError reports enabled bearer authentication without the token required to authenticate requests.

func (*AuthenticationTokenRequiredError) Error

type DashboardConfig

type DashboardConfig struct {
	Enabled bool
	Scopes  []DashboardScope
}

type DashboardScope

type DashboardScope struct {
	ScopeID     string `json:"scope_id"`
	DisplayName string `json:"display_name"`
}

type DatabaseConfig

type DatabaseConfig struct {
	Kind      string
	SQLite    SQLiteDatabaseConfig
	OceanBase OceanBaseDatabaseConfig
	SeekDB    SeekDBDatabaseConfig
}

type Dependencies

type Dependencies struct {
	MemoryCandidates     memory.CandidatePipeline
	ExperienceCandidates experience.CandidatePipeline
	ExperienceGenerator  experience.Generator
	SkillGenerator       skill.Generator
	HandoffGenerator     handoff.GenerationPipeline
	EmbeddingModel       inference.EmbeddingModel
	MemoryReranker       memory.Reranker
	ExternalSkills       skill.ExternalProvider
	HTTPClient           *http.Client
	Clock                func() time.Time
	IDFactory            func(string) (string, error)
	Logger               *slog.Logger
	TracerProvider       trace.TracerProvider
}

Dependencies are deliberate extension points for deterministic tests and custom deployments. Nil values are assembled from InferenceConfig where possible; they are not service locators and do not own lifecycle.

type ExternalSkillRoot

type ExternalSkillRoot struct {
	RootID              string `json:"root_id"`
	InstallationScope   string `json:"installation_scope"`
	Path                string `json:"path"`
	AllowManagedPublish bool   `json:"allow_managed_publish"`
}

type ExternalSkillTarget

type ExternalSkillTarget struct {
	TargetID            string `json:"target_id"`
	AgentKind           string `json:"agent_kind"`
	InstallationScope   string `json:"installation_scope"`
	Path                string `json:"path"`
	AllowManagedPublish bool   `json:"allow_managed_publish"`
}

type ExternalSkillsConfig

type ExternalSkillsConfig struct {
	HostID     string
	Targets    []ExternalSkillTarget
	CodexRoots []ExternalSkillRoot
}

type HTTPConfig

type HTTPConfig struct {
	Host string
	Port int
}

func (HTTPConfig) Address

func (c HTTPConfig) Address() string

type HTTPConfigOverride

type HTTPConfigOverride struct {
	Host *string
	Port *int
}

HTTPConfigOverride contains only command-line values that were explicitly provided and must be merged before ProcessConfig validation.

type HTTPOptions

type HTTPOptions struct {
	BearerToken         string
	HandoffReportRoutes bool
	TracerProvider      trace.TracerProvider
	MeterProvider       metric.MeterProvider
	Logger              *slog.Logger
	AccessLog           bool
	MCP                 MCPOptions
	// contains filtered or unexported fields
}

type HandoffReportConfig

type HandoffReportConfig struct{ Enabled bool }

type InferenceConfig

type InferenceConfig struct {
	GenerationModel        string
	GenerationTimeout      time.Duration
	GenerationMaxRequests  int
	EmbeddingModel         string
	EmbeddingProfileID     string
	EmbeddingDimension     int
	EmbeddingNormalization string
	EmbeddingTimeout       time.Duration
	EmbeddingBatchSize     int
}

type LoggingConfig

type LoggingConfig struct {
	Level  string
	Format string
	Access bool
}

type MCPConfig

type MCPConfig struct {
	Enabled bool
	Path    string
}

type MCPOptions

type MCPOptions struct {
	Enabled        bool
	Path           string
	Version        string
	Stateless      bool
	JSONResponse   bool
	SessionTimeout time.Duration
	Logger         *slog.Logger
}

MCPOptions controls the optional MCP Streamable HTTP route. Path defaults to /mcp. A disabled MCP surface is not mounted and therefore returns 404.

type MetricsConfig

type MetricsConfig struct{ Enabled bool }

type OceanBaseDatabaseConfig

type OceanBaseDatabaseConfig struct {
	URL          string
	MaxOpenConns int
	MaxIdleConns int
	MaxLifetime  time.Duration
}

type ProcessConfig

type ProcessConfig struct {
	HTTP                            HTTPConfig
	MCP                             MCPConfig
	Auth                            AuthConfig
	AllowUnauthenticatedNonLoopback bool
	Dashboard                       DashboardConfig
	Logging                         LoggingConfig
	Metrics                         MetricsConfig
	Tracing                         TracingConfig
	Runtime                         RuntimeConfig
	Database                        DatabaseConfig
	HandoffReport                   HandoffReportConfig
	Inference                       InferenceConfig
	ExternalSkills                  ExternalSkillsConfig
	SchedulerPath                   string
}

ProcessConfig is the validated process-owned configuration. Domain packages intentionally never read it or inspect the environment.

func DefaultConfig

func DefaultConfig() (ProcessConfig, error)

DefaultConfig returns the same validated defaults used by LoadConfig, without consulting POWERCONTEXT_SERVER_* overrides.

func LoadConfig

func LoadConfig() (ProcessConfig, error)

LoadConfig overlays POWERCONTEXT_SERVER_* values on the frozen Python defaults. Nested object fields use the same one-level underscore spelling; slices use JSON, matching pydantic-settings' environment representation.

func LoadConfigWithHTTPOverride

func LoadConfigWithHTTPOverride(override HTTPConfigOverride) (ProcessConfig, error)

LoadConfigWithHTTPOverride overlays explicitly provided HTTP command-line values before running the same final validation used by LoadConfig.

func (ProcessConfig) Validate

func (c ProcessConfig) Validate() error

type RuntimeConfig

type RuntimeConfig struct {
	ScopeCacheSize               int
	SourceWindowLimit            int64
	MemoryExtractionProfile      memory.ExtractionProfile
	MemoryRerankEnabled          bool
	MemoryRerankCandidateLimit   int
	SourceWindowInterval         *time.Duration
	ExperienceIncubationInterval *time.Duration
}

type SQLiteDatabaseConfig

type SQLiteDatabaseConfig struct {
	URL             string
	BusyTimeout     time.Duration
	JournalMode     string
	ForeignKeys     bool
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
}

type SeekDBDatabaseConfig

type SeekDBDatabaseConfig struct {
	Path         string
	Database     string
	LibraryPath  string
	MaxOpenConns int
	MaxIdleConns int
	MaxLifetime  time.Duration
}

type TracingConfig

type TracingConfig struct{ Enabled bool }

type UnauthenticatedNonLoopbackBindError

type UnauthenticatedNonLoopbackBindError struct{}

UnauthenticatedNonLoopbackBindError reports a Server bind that would expose unauthenticated HTTP or MCP traffic outside the local machine.

func (*UnauthenticatedNonLoopbackBindError) Error

Jump to

Keyboard shortcuts

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