appserver

package
v0.13.12 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 60 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AIServiceUnavailableErrorCode         = "AI_SERVICE_UNAVAILABLE"
	AIReadinessContractErrorReasonCode    = "ai_readiness_contract_error"
	AIServiceStartupErrorReasonCode       = "ai_service_startup_error"
	AIHostThreadSettingsMissingReasonCode = "host_thread_settings_missing"
)
View Source
const (
	// LocalUIChannelID is the synthetic session channel used by Local UI Env App requests.
	LocalUIChannelID = "local-ui"
)
View Source
const LocalUIPortForwardBrowserSessionCookieName = "__redeven_web_service_browser_session_v1"

LocalUIPortForwardBrowserSessionCookieName is reserved for Runtime-managed browser authorization and must never cross the Web Service proxy boundary.

Variables

View Source
var (
	ErrAIServiceUnavailable = errors.New("AI service is unavailable")
	ErrAIRetryInProgress    = errors.New("AI readiness check is already in progress")
)

Functions

func LocalEnvSessionMeta added in v0.7.2

func LocalEnvSessionMeta(configPath string) *session.Meta

LocalEnvSessionMeta returns the synthetic Env App session used by Local UI routes.

func NativeCodeSpaceOrigin added in v0.13.0

func NativeCodeSpaceOrigin(raw string) (*url.URL, bool)

NativeCodeSpaceOrigin accepts only Desktop-owned loopback presentation origins. This value controls editor Host presentation, never the Runtime dial target.

func NewNativeCodeSpaceHandler added in v0.13.0

func NewNativeCodeSpaceHandler(binding NativeCodeSpaceBinding) (http.Handler, func(), error)

NewNativeCodeSpaceHandler serves only the bound editor, never the product router. Its caller owns request authorization and must cancel its binding on revocation.

func StripLocalUIPortForwardBrowserSessionCookie added in v0.13.0

func StripLocalUIPortForwardBrowserSessionCookie(r *http.Request)

StripLocalUIPortForwardBrowserSessionCookie removes every Runtime browser authorization cookie before a request is forwarded to a user service.

func WithLocalUICodeSpaceRoute

func WithLocalUICodeSpaceRoute(r *http.Request, codeSpaceID string) *http.Request

func WithLocalUIEnvRoute

func WithLocalUIEnvRoute(r *http.Request) *http.Request

func WithLocalUIPluginRoute added in v0.7.2

func WithLocalUIPluginRoute(r *http.Request, channelID string) *http.Request

func WithLocalUIPortForwardOrigin added in v0.13.0

func WithLocalUIPortForwardOrigin(r *http.Request, forwardID string) *http.Request

func WithLocalUIPortForwardRoute

func WithLocalUIPortForwardRoute(r *http.Request, forwardID string) *http.Request

Types

type AIOrphanRootMaintenanceProvider added in v0.11.0

type AIOrphanRootMaintenanceProvider interface {
	ReviewOrphanCanonicalRoots(context.Context) (ai.OrphanCanonicalRootReview, error)
	AdoptOrphanCanonicalRoot(context.Context, ai.AdoptOrphanCanonicalRootRequest) (int, error)
	DeleteOrphanCanonicalRoot(context.Context, ai.DeleteOrphanCanonicalRootRequest) (int, error)
}

type AIReadinessSnapshot added in v0.11.0

type AIReadinessSnapshot struct {
	Component    string           `json:"component,omitempty"`
	State        AIReadinessState `json:"state"`
	ReasonCode   string           `json:"reason_code,omitempty"`
	Retryable    bool             `json:"retryable"`
	SafeToRetry  bool             `json:"safe_to_retry"`
	IssueCount   int              `json:"issue_count,omitempty"`
	TraceID      string           `json:"trace_id,omitempty"`
	StartupPhase string           `json:"startup_phase,omitempty"`
	RetryReason  string           `json:"retry_reason,omitempty"`
}

AIReadinessSnapshot contains only Redeven-owned, sanitized availability facts. It must never contain Floret Store or Agent snapshots.

type AIReadinessState added in v0.11.0

type AIReadinessState string
const (
	AIReadinessUnavailable AIReadinessState = "unavailable"
	AIReadinessInspecting  AIReadinessState = "inspecting"
	AIReadinessOptimizing  AIReadinessState = "optimizing"
	AIReadinessMigrating   AIReadinessState = "migrating"
	AIReadinessVerifying   AIReadinessState = "verifying"
	AIReadinessRecovering  AIReadinessState = "recovering"
	AIReadinessBackingUp   AIReadinessState = "backing_up"
	AIReadinessRestoring   AIReadinessState = "restoring"
	AIReadinessReady       AIReadinessState = "ready"
	AIReadinessDegraded    AIReadinessState = "degraded"
	AIReadinessBlocked     AIReadinessState = "blocked"
)

type AIServiceProvider added in v0.11.0

type AIServiceProvider interface {
	AcquireAIService(context.Context) (*ai.Service, context.Context, uint64, func(), error)
	AIReadiness() AIReadinessSnapshot
	RetryAIReadiness() error
	UpdateAIServiceStartupOptions(AIServiceStartupOptions)
}

type AIServiceStartupOptions added in v0.11.0

type AIServiceStartupOptions struct {
	Config          *config.AIConfig
	AgentHomeDir    string
	Shell           string
	FilesystemScope *filesystemscope.Registry
}

AIServiceStartupOptions contains the Redeven-owned inputs that may change between service generations. It carries no Store or Agent lifecycle state.

type AIStorageMaintenanceProvider added in v0.13.0

type AIStorageMaintenanceProvider interface {
	ListFlowerSnapshots(context.Context) ([]ai.FlowerSnapshotSummary, error)
	RestoreFlowerSnapshot(string) error
}

type Backend

type Backend interface {
	ListSpaces(ctx context.Context) ([]SpaceStatus, error)
	CreateSpace(ctx context.Context, req CreateSpaceRequest) (*SpaceStatus, error)
	UpdateSpace(ctx context.Context, codeSpaceID string, req UpdateSpaceRequest) (*SpaceStatus, error)
	DeleteSpace(ctx context.Context, codeSpaceID string) error
	StartSpace(ctx context.Context, codeSpaceID string) (*SpaceStatus, error)
	StopSpace(ctx context.Context, codeSpaceID string) error
	ResolveCodeServerPort(ctx context.Context, codeSpaceID string) (int, error)
	BindRunningCodeSpace(ctx context.Context, codeSpaceID string) (NativeCodeSpaceBinding, error)
	CodeRuntimeStatus(ctx context.Context) (CodeRuntimeStatus, error)
	CreateCodeRuntimeSetupOperation(ctx context.Context, operationID string, installMethod codeserver.BrowserEditorInstallMethod, manifest *CodeRuntimeArtifactManifest) (CodeRuntimeSetupOperation, error)
	AppendCodeRuntimeSetupChunk(ctx context.Context, operationID string, chunkIndex int64, body io.Reader) (CodeRuntimeSetupChunkResult, error)
	CompleteCodeRuntimeSetupOperation(ctx context.Context, operationID string) (CodeRuntimeStatus, error)
	CancelCodeRuntimeSetupOperation(ctx context.Context, operationID string) (CodeRuntimeStatus, error)
	SelectCodeRuntimeVersion(ctx context.Context, version string) (CodeRuntimeStatus, error)
	RemoveCodeRuntimeVersion(ctx context.Context, version string) (CodeRuntimeStatus, error)
	CancelCodeRuntimeOperation(ctx context.Context) (CodeRuntimeStatus, error)
}

type CodeRuntimeSetupChunkResult added in v0.10.0

type CodeRuntimeSetupChunkResult = codeserver.WorkspaceEngineSetupChunkResult

type CodeRuntimeSetupOperation added in v0.10.0

type CodeRuntimeSetupOperation = codeserver.WorkspaceEngineSetupOperation

type CodeRuntimeSetupOperationRequest added in v0.10.0

type CodeRuntimeSetupOperationRequest struct {
	OperationID   string                                `json:"operation_id"`
	InstallMethod codeserver.BrowserEditorInstallMethod `json:"install_method"`
	Manifest      *CodeRuntimeArtifactManifest          `json:"manifest,omitempty"`
}

type CodeRuntimeStatus

type CodeRuntimeStatus = codeserver.RuntimeStatus

type CodeRuntimeVersionRequest

type CodeRuntimeVersionRequest struct {
	Version string `json:"version"`
}

type CreateSpaceRequest

type CreateSpaceRequest struct {
	Path        string `json:"path"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

type NativeCodeSpaceBinding added in v0.13.0

type NativeCodeSpaceBinding struct {
	CodeSpaceID     string
	InstanceID      string
	WorkspacePath   string
	Port            int
	Context         context.Context
	AdmitConnection func() (func(), bool)
}

NativeCodeSpaceBinding is resolved by the lifecycle owner after authorization. Context ends before the instance can be stopped or replaced; ports are never identity.

type Options

type Options struct {
	Logger               *slog.Logger
	ListenAddr           string
	DistFS               stdfs.FS
	Backend              Backend
	PortForward          PortForwardBackend
	ManagedWebServices   managedwebservice.Backend
	HostApplications     hostapps.Backend
	ContainerResources   *containerresource.Service
	AIServiceProvider    AIServiceProvider
	BrowserRuntime       *ai.ComputerUseRuntime
	Notes                *notes.Service
	WorkbenchLayout      *workbenchlayout.Service
	Terminal             *terminal.Manager
	Audit                *auditlog.Store
	Diagnostics          *diagnostics.Store
	ResolveSessionMeta   func(channelID string) (*session.Meta, bool)
	AcquirePluginSession func(channelID string) (*session.Meta, func(), bool)
	EndPluginSession     func(channelID string)
	// ConfigPath is the absolute path to the runtime config file.
	// It is used to read and persist settings updates initiated from the Env App UI.
	ConfigPath string
	// SecretsStore holds user-managed secrets (such as AI provider API keys).
	// If nil, the app server will derive a default secrets path from ConfigPath.
	SecretsStore *settings.SecretsStore
	// PluginPlatform is the released ReDevPlugin HTTP handler mounted behind Redeven routes.
	PluginPlatform        http.Handler
	PluginMarketSnapshot  func(context.Context) (pluginmarket.Snapshot, error)
	PluginMarketRefresh   func(context.Context) (pluginmarket.Snapshot, error)
	PluginMarketSubscribe func(context.Context, int64) ([]pluginmarket.RefreshEvent, <-chan pluginmarket.RefreshEvent, error)
	PluginMarketDetail    func(context.Context, string) (pluginmarket.PluginDetail, int64, error)
	PluginMarketIcon      func(context.Context, string, string) (pluginmarket.IconAsset, error)
	// AgentHomeDir is the canonical absolute path to the default home directory.
	AgentHomeDir    string
	FilesystemScope *filesystemscope.Registry
}

type PortForwardBackend

type PortForwardBackend interface {
	ListForwards(ctx context.Context) ([]pfregistry.Forward, error)
	GetForward(ctx context.Context, forwardID string) (*pfregistry.Forward, error)
	OpenForwardSession(ctx context.Context, req portforward.OpenForwardSessionRequest) (*portforward.ForwardSession, error)
	SaveForwardSession(ctx context.Context, forwardID string, req portforward.SaveForwardSessionRequest) (*pfregistry.Forward, error)
	CreateForward(ctx context.Context, req portforward.CreateForwardRequest) (*pfregistry.Forward, error)
	UpdateForward(ctx context.Context, forwardID string, req portforward.UpdateForwardRequest) (*pfregistry.Forward, error)
	DeleteForward(ctx context.Context, forwardID string) error
	TouchLastOpened(ctx context.Context, forwardID string) (*pfregistry.Forward, error)
}

type Server

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

func New

func New(opts Options) (*Server, error)

func (*Server) Close

func (g *Server) Close() error

func (*Server) ClosePluginSessionConnections added in v0.11.0

func (g *Server) ClosePluginSessionConnections(channelID string)

func (*Server) CodeRuntimeStatus

func (g *Server) CodeRuntimeStatus(ctx context.Context) (CodeRuntimeStatus, error)

func (*Server) EnvAppShellReadinessError

func (g *Server) EnvAppShellReadinessError() error

EnvAppShellReadinessError validates that the embedded Env App shell can be opened by Desktop before the runtime advertises open-readiness.

func (*Server) EnvAppShellReady

func (g *Server) EnvAppShellReady() bool

EnvAppShellReady reports whether the embedded Env App shell is complete.

func (*Server) LocalNativeCodeSpaceBinding added in v0.13.0

func (g *Server) LocalNativeCodeSpaceBinding(w http.ResponseWriter, r *http.Request, id string) (NativeCodeSpaceBinding, bool)

LocalNativeCodeSpaceBinding applies the current Code App permission cap before disclosing or resolving a running instance. Listener and AccessGate admission remain owned by Local UI.

func (*Server) PluginPlatformEnabled added in v0.7.2

func (g *Server) PluginPlatformEnabled() bool

func (*Server) ServeHTTP

func (g *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (g *Server) Start(ctx context.Context) error

func (*Server) URL

func (g *Server) URL() string

type SpaceStatus

type SpaceStatus struct {
	CodeSpaceID        string `json:"code_space_id"`
	Name               string `json:"name"`
	Description        string `json:"description"`
	WorkspacePath      string `json:"workspace_path"`
	CodePort           int    `json:"code_port"`
	CreatedAtUnixMs    int64  `json:"created_at_unix_ms"`
	UpdatedAtUnixMs    int64  `json:"updated_at_unix_ms"`
	LastOpenedAtUnixMs int64  `json:"last_opened_at_unix_ms"`

	Running bool `json:"running"`
	PID     int  `json:"pid"`
}

type UpdateSpaceRequest

type UpdateSpaceRequest struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
}

Jump to

Keyboard shortcuts

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