server

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT

* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT

* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT

* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port        int
	Token       string // auth token (empty = no auth)
	TLSCertFile string
	TLSKeyFile  string
	Provider    string
	Model       string
}

Config holds server configuration.

type Handler

type Handler struct {
	pb.UnimplementedChatCLIServiceServer
	// contains filtered or unexported fields
}

Handler implements the ChatCLIService gRPC server.

func NewHandler

func NewHandler(llmMgr manager.LLMManager, sessionStore SessionStore, logger *zap.Logger, provider, model string) *Handler

NewHandler creates a new gRPC handler.

func (*Handler) DeleteSession

func (h *Handler) DeleteSession(ctx context.Context, req *pb.DeleteSessionRequest) (*pb.DeleteSessionResponse, error)

DeleteSession removes a saved session.

func (*Handler) GetServerInfo

func (h *Handler) GetServerInfo(ctx context.Context, req *pb.GetServerInfoRequest) (*pb.GetServerInfoResponse, error)

GetServerInfo returns server metadata.

func (*Handler) GetWatcherStatus

GetWatcherStatus returns the K8s watcher status.

func (*Handler) Health

func (h *Handler) Health(ctx context.Context, req *pb.HealthRequest) (*pb.HealthResponse, error)

Health returns the server health status.

func (*Handler) InteractiveSession

func (h *Handler) InteractiveSession(stream pb.ChatCLIService_InteractiveSessionServer) error

InteractiveSession handles bidirectional streaming for interactive mode.

func (*Handler) ListSessions

func (h *Handler) ListSessions(ctx context.Context, req *pb.ListSessionsRequest) (*pb.ListSessionsResponse, error)

ListSessions returns all saved session names.

func (*Handler) LoadSession

func (h *Handler) LoadSession(ctx context.Context, req *pb.LoadSessionRequest) (*pb.LoadSessionResponse, error)

LoadSession loads a saved session.

func (*Handler) SaveSession

func (h *Handler) SaveSession(ctx context.Context, req *pb.SaveSessionRequest) (*pb.SaveSessionResponse, error)

SaveSession saves the conversation history.

func (*Handler) SendPrompt

func (h *Handler) SendPrompt(ctx context.Context, req *pb.SendPromptRequest) (*pb.SendPromptResponse, error)

SendPrompt handles a single prompt request.

func (*Handler) SetWatcher

func (h *Handler) SetWatcher(cfg WatcherConfig)

SetWatcher configures full watcher integration with context, status, and stats.

func (*Handler) SetWatcherContext

func (h *Handler) SetWatcherContext(fn func() string)

SetWatcherContext configures a function that provides K8s watcher context to be prepended to all LLM prompts.

func (*Handler) StreamPrompt

StreamPrompt handles a streaming prompt request.

type Server

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

Server wraps the gRPC server and its dependencies.

func New

func New(cfg Config, llmMgr manager.LLMManager, sessionStore SessionStore, logger *zap.Logger) *Server

New creates a new ChatCLI gRPC server.

func (*Server) SetWatcher

func (s *Server) SetWatcher(cfg WatcherConfig)

SetWatcher configures full K8s watcher integration with context, status, and stats.

func (*Server) SetWatcherContext

func (s *Server) SetWatcherContext(fn func() string)

SetWatcherContext configures K8s watcher context injection for all prompts.

func (*Server) Start

func (s *Server) Start() error

Start begins listening and serving gRPC requests. It blocks until the server is stopped via signal or Stop().

func (*Server) Stop

func (s *Server) Stop()

Stop gracefully stops the server.

type SessionStore

type SessionStore interface {
	SaveSession(name string, history []models.Message) error
	LoadSession(name string) ([]models.Message, error)
	ListSessions() ([]string, error)
	DeleteSession(name string) error
}

SessionStore abstracts session persistence for testability.

type TokenAuthInterceptor

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

TokenAuthInterceptor validates Bearer tokens from gRPC metadata.

func NewTokenAuthInterceptor

func NewTokenAuthInterceptor(token string, logger *zap.Logger) *TokenAuthInterceptor

NewTokenAuthInterceptor creates a new auth interceptor. If token is empty, authentication is disabled (all requests allowed).

func (*TokenAuthInterceptor) Stream

Stream returns a grpc.StreamServerInterceptor that validates the Bearer token.

func (*TokenAuthInterceptor) Unary

Unary returns a grpc.UnaryServerInterceptor that validates the Bearer token.

type WatcherConfig

type WatcherConfig struct {
	ContextFunc func() string                                    // full context for LLM
	StatusFunc  func() string                                    // compact status summary
	StatsFunc   func() (alertCount, snapshotCount, podCount int) // numeric stats
	Deployment  string
	Namespace   string
}

WatcherConfig holds the functions and metadata for K8s watcher integration.

Jump to

Keyboard shortcuts

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