server

package
v0.0.0-...-c9f6cb5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCaptureStreamID = "mic"

DefaultCaptureStreamID is the default stream identifier for audio capture.

View Source
const DiagnosticsCaptureUnavailable = "voice capture unavailable: check STT adapter configuration"

DiagnosticsCaptureUnavailable is the diagnostics message when voice capture is not ready. TODO: VoiceReadiness currently returns only booleans; once it carries per-slot failure reasons, replace this constant with a dynamic message.

View Source
const DiagnosticsPlaybackUnavailable = "voice playback unavailable: check TTS adapter configuration"

DiagnosticsPlaybackUnavailable is the diagnostics message when voice playback is not ready. TODO: both constants use static messages — replace with dynamic per-slot diagnostics when VoiceReadiness provides detailed failure reasons.

Variables

View Source
var ErrAudioStreamExists = errors.New("audio stream already exists")

ErrAudioStreamExists signals that an audio ingress stream already exists for the given identifiers.

Functions

func DefaultCaptureFormat

func DefaultCaptureFormat() eventbus.AudioFormat

DefaultCaptureFormat returns a copy of the default audio capture format.

func NewConnectTranscoder

func NewConnectTranscoder(grpcServer *grpc.Server) (*vanguard.Transcoder, error)

NewConnectTranscoder wraps the given gRPC server with a Vanguard transcoder that exposes all registered services via Connect RPC (HTTP/JSON) protocol. This enables mobile and web clients to call unary RPCs using standard Fetch API.

The transcoder reuses the same service implementations and interceptors (auth, language) already registered on the gRPC server — zero business logic duplication.

Note: the first call registers a "json" codec via encoding.RegisterCodec, which is a process-wide, irreversible side effect. Standard gRPC uses the "proto" codec so this does not affect existing gRPC clients.

func RegisterGRPCServices

func RegisterGRPCServices(api *APIServer, registrar grpc.ServiceRegistrar)

Types

type APIServer

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

APIServer provides the shared business logic and state for the Nupi daemon API. It is used by gRPC services and the transport gateway.

func NewAPIServer

func NewAPIServer(sessionManager SessionManager, configStore ConfigStore, runtime RuntimeInfoProvider) (*APIServer, error)

NewAPIServer creates a new API server.

func (*APIServer) AddTransportListener

func (s *APIServer) AddTransportListener(fn func())

AddTransportListener registers a callback invoked after transport config changes.

func (*APIServer) AudioEgress

func (s *APIServer) AudioEgress() AudioPlaybackController

AudioEgress exposes the audio egress controller for components outside the server package.

func (*APIServer) AudioIngress

func (s *APIServer) AudioIngress() AudioCaptureProvider

AudioIngress exposes the audio ingress provider for components outside the server package.

func (*APIServer) AuthRequired

func (s *APIServer) AuthRequired() bool

AuthRequired reports whether transport-level authentication is enforced.

func (*APIServer) AuthenticateToken

func (s *APIServer) AuthenticateToken(token string) (storedToken, bool)

AuthenticateToken returns token metadata if present in the allowlist.

func (*APIServer) AuthorizeGRPCMethod

func (s *APIServer) AuthorizeGRPCMethod(ctx context.Context, fullMethod string) error

AuthorizeGRPCMethod enforces method-level role requirements for gRPC calls. Uses default-deny: methods not listed in any authorization map are rejected.

func (*APIServer) ContextWithToken

func (s *APIServer) ContextWithToken(ctx context.Context, token storedToken) context.Context

ContextWithToken attaches token metadata to the provided context.

func (*APIServer) CurrentTransportSnapshot

func (s *APIServer) CurrentTransportSnapshot() TransportSnapshot

CurrentTransportSnapshot returns the currently applied transport configuration.

func (*APIServer) EventBus

func (s *APIServer) EventBus() *eventbus.Bus

EventBus exposes the event bus for components outside the server package.

func (*APIServer) Prepare

func (s *APIServer) Prepare(ctx context.Context) (*PreparedTransport, error)

Prepare resolves transport configuration from the store and returns the current transport settings. It validates bindings, TLS, and auth tokens.

func (*APIServer) PublishAudioInterrupt

func (s *APIServer) PublishAudioInterrupt(sessionID, streamID, reason string, metadata map[string]string)

PublishAudioInterrupt publishes an audio interrupt event on the event bus.

func (*APIServer) RequestShutdown

func (s *APIServer) RequestShutdown()

RequestShutdown triggers a graceful daemon shutdown using the registered shutdown function.

func (*APIServer) ResizeManager

func (s *APIServer) ResizeManager() *termresize.Manager

ResizeManager exposes the resize manager for components outside the server package.

func (*APIServer) SessionMgr

func (s *APIServer) SessionMgr() SessionManager

SessionMgr exposes the session manager for components outside the server package.

func (*APIServer) SetAdaptersController

func (s *APIServer) SetAdaptersController(controller AdaptersController)

SetAdaptersController wires the adapter controller.

func (*APIServer) SetAudioEgress

func (s *APIServer) SetAudioEgress(controller AudioPlaybackController)

SetAudioEgress wires the audio egress handler.

func (*APIServer) SetAudioIngress

func (s *APIServer) SetAudioIngress(provider AudioCaptureProvider)

SetAudioIngress wires the audio ingress handler.

func (*APIServer) SetConversationStore

func (s *APIServer) SetConversationStore(store ConversationStore)

SetConversationStore wires the conversation state provider.

func (*APIServer) SetEventBus

func (s *APIServer) SetEventBus(bus *eventbus.Bus)

SetEventBus wires the event bus.

func (*APIServer) SetPluginReloader

func (s *APIServer) SetPluginReloader(reloader PluginReloader)

SetPluginReloader wires the plugin reloader. Must be called before Start.

func (*APIServer) SetShutdownFunc

func (s *APIServer) SetShutdownFunc(fn func(context.Context) error)

SetShutdownFunc registers a handler invoked when a shutdown is requested.

func (*APIServer) UpdateActualGRPCPort

func (s *APIServer) UpdateActualGRPCPort(ctx context.Context, port int)

UpdateActualGRPCPort persists the effective gRPC port into the configuration store.

func (*APIServer) ValidateAuthToken

func (s *APIServer) ValidateAuthToken(token string) bool

ValidateAuthToken verifies the supplied API token against the active allowlist.

type AdaptersController

type AdaptersController interface {
	Overview(ctx context.Context) ([]adapters.BindingStatus, error)
	StartSlot(ctx context.Context, slot adapters.Slot) (*adapters.BindingStatus, error)
	StopSlot(ctx context.Context, slot adapters.Slot) (*adapters.BindingStatus, error)
}

AdaptersController exposes adapter lifecycle operations required by the API.

type AudioCaptureProvider

type AudioCaptureProvider interface {
	OpenStream(sessionID, streamID string, format eventbus.AudioFormat, metadata map[string]string) (AudioCaptureStream, error)
}

AudioCaptureProvider exposes operations required by the gRPC layer to accept audio input.

type AudioCaptureStream

type AudioCaptureStream interface {
	Write([]byte) error
	Close() error
}

AudioCaptureStream models an open audio ingress stream.

type AudioPlaybackController

type AudioPlaybackController interface {
	DefaultStreamID() string
	PlaybackFormat() eventbus.AudioFormat
	Interrupt(sessionID, streamID, reason string, metadata map[string]string)
}

AudioPlaybackController exposes playback control operations used by API handlers.

type ConfigStore

type ConfigStore interface {
	GetTransportConfig(ctx context.Context) (configstore.TransportConfig, error)
	SaveTransportConfig(ctx context.Context, cfg configstore.TransportConfig) error
	ListAdapters(ctx context.Context) ([]configstore.Adapter, error)
	ListAdapterBindings(ctx context.Context) ([]configstore.AdapterBinding, error)
	UpsertAdapter(ctx context.Context, adapter configstore.Adapter) error
	UpsertAdapterEndpoint(ctx context.Context, endpoint configstore.AdapterEndpoint) error
	SetActiveAdapter(ctx context.Context, slot string, adapterID string, config map[string]any) error
	ClearAdapterBinding(ctx context.Context, slot string) error
	AdapterExists(ctx context.Context, adapterID string) (bool, error)
	EnsureRequiredAdapterSlots(ctx context.Context) (configstore.MigrationResult, error)
	EnsureAudioSettings(ctx context.Context) (bool, error)
	VoiceReadiness(ctx context.Context) (configstore.VoiceReadiness, error)
	LoadSecuritySettings(ctx context.Context, keys ...string) (map[string]string, error)
	SaveSecuritySettings(ctx context.Context, values map[string]string) error
	QuickstartStatus(ctx context.Context) (bool, *time.Time, error)
	PendingQuickstartSlots(ctx context.Context) ([]string, error)
	MarkQuickstartCompleted(ctx context.Context, complete bool) error
	SavePushToken(ctx context.Context, deviceID, token string, enabledEvents []string, authTokenID string) error
	SavePushTokenOwned(ctx context.Context, deviceID, token string, enabledEvents []string, authTokenID string) (bool, error)
	GetPushToken(ctx context.Context, deviceID string) (*configstore.PushToken, error)
	DeletePushToken(ctx context.Context, deviceID string) error
	DeletePushTokenOwned(ctx context.Context, deviceID, authTokenID string) (bool, error)
	DeletePushTokenIfMatch(ctx context.Context, deviceID, token string) (bool, error)
	DeletePushTokensByAuthToken(ctx context.Context, authTokenID string) error
	DeleteAllPushTokens(ctx context.Context) error
	ListPushTokens(ctx context.Context) ([]configstore.PushToken, error)
	ListPushTokensForEvent(ctx context.Context, eventType string) ([]configstore.PushToken, error)
}

ConfigStore abstracts configuration storage operations used by API handlers and gRPC services.

type ConversationStore

type ConversationStore interface {
	Context(sessionID string) []eventbus.ConversationTurn
	Slice(sessionID string, offset, limit int) (int, []eventbus.ConversationTurn)
	GlobalContext() []eventbus.ConversationTurn
	GlobalSlice(offset, limit int) (int, []eventbus.ConversationTurn)
}

ConversationStore exposes a readonly view of conversation history.

type GRPCStreamSink

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

GRPCStreamSink implements pty.OutputSink for streaming session output over gRPC.

func (*GRPCStreamSink) Close

func (s *GRPCStreamSink) Close()

func (*GRPCStreamSink) Write

func (s *GRPCStreamSink) Write(data []byte) error

type PluginReloader

type PluginReloader interface {
	Reload(ctx context.Context) error
}

PluginReloader reloads all plugin indices (pipeline cleaners, tool handlers, index).

type PreparedTransport

type PreparedTransport struct {
	Binding     string
	GRPCBinding string
	GRPCPort    int
	UseTLS      bool
	CertPath    string
	KeyPath     string
}

PreparedTransport holds transport parameters resolved by Prepare().

type RuntimeInfoProvider

type RuntimeInfoProvider interface {
	GRPCPort() int
	ConnectPort() int
	StartTime() time.Time
}

RuntimeInfoProvider defines methods required to expose runtime metadata.

type SessionManager

type SessionManager interface {
	ListSessions() []*session.Session
	CreateSession(opts pty.StartOptions, inspect bool) (*session.Session, error)
	GetSession(id string) (*session.Session, error)
	KillSession(id string) error
	WriteToSession(id string, data []byte) error
	ResizeSession(id string, rows, cols int) error
	GetRecordingStore() *recording.Store
	AddEventListener(listener session.SessionEventListener)
	AttachToSession(id string, sink pty.OutputSink, includeHistory bool) error
	DetachFromSession(id string, sink pty.OutputSink) error
}

SessionManager abstracts session lifecycle operations used by gRPC services.

type TransportSnapshot

type TransportSnapshot struct {
	Binding        string
	TLSCertPath    string
	TLSKeyPath     string
	GRPCBinding    string
	GRPCPort       int
	TLSCertModTime time.Time
	TLSKeyModTime  time.Time
}

TransportSnapshot captures the runtime server transport settings.

func (TransportSnapshot) EqualConfig

func (snap TransportSnapshot) EqualConfig(cfg configstore.TransportConfig) bool

EqualConfig compares the snapshot with a transport configuration fetched from the store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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