grpcserver

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package grpcserver provides analytics gRPC service.

Package grpcserver provides gRPC compression service.

Index

Constants

This section is empty.

Variables

View Source
var CompressionService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "tokman.CompressionService",
	HandlerType: (*CompressionService)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Compress",
			Handler:    CompressionService_Compress_Handler,
		},
		{
			MethodName: "GetStats",
			Handler:    CompressionService_GetStats_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "StreamCompress",
			Handler:       CompressionService_StreamCompress_Handler,
			ServerStreams: true,
			ClientStreams: true,
		},
	},
	Metadata: "compression.proto",
}

CompressionService_ServiceDesc is the grpc.ServiceDesc.

Functions

func CompressionService_Compress_Handler

func CompressionService_Compress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error)

Handler implementations.

func CompressionService_GetStats_Handler

func CompressionService_GetStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error)

func CompressionService_StreamCompress_Handler

func CompressionService_StreamCompress_Handler(srv interface{}, stream grpc.ServerStream) error

func RegisterAnalyticsService

func RegisterAnalyticsService(server *grpc.Server, tracker AnalyticsTracker, registry *LayerRegistry)

RegisterAnalyticsService registers the analytics service with a gRPC server.

func RegisterCompressionServiceServer

func RegisterCompressionServiceServer(s *grpc.Server, srv *CompressionService)

RegisterCompressionServiceServer registers the service.

Types

type AnalyticsServer

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

AnalyticsServer implements the Analytics gRPC service.

func NewAnalyticsServer

func NewAnalyticsServer(tracker AnalyticsTracker, registry *LayerRegistry) *AnalyticsServer

NewAnalyticsServer creates a new analytics server.

func (*AnalyticsServer) ExportAnalytics

func (s *AnalyticsServer) ExportAnalytics(ctx context.Context, req *ExportRequest) (*ExportResponse, error)

ExportAnalytics exports analytics data in various formats.

func (*AnalyticsServer) GetCompressionRatio

GetCompressionRatio returns compression ratio analysis.

func (*AnalyticsServer) GetCostAnalysis

GetCostAnalysis returns cost estimation analytics.

func (*AnalyticsServer) GetLayerPerformance

GetLayerPerformance returns layer performance metrics.

func (*AnalyticsServer) GetUsageReport

GetUsageReport returns comprehensive usage analytics.

func (*AnalyticsServer) StreamRealtimeAnalytics

func (s *AnalyticsServer) StreamRealtimeAnalytics(req *RealtimeStreamRequest, stream chan<- *RealtimeEvent) error

StreamRealtimeAnalytics streams real-time analytics data.

type AnalyticsTracker

type AnalyticsTracker interface {
	GetDailySavings(cmd string, days int) ([]DailyRecord, error)
	GetLayerStats() map[string]LayerStat
	TotalTokensSaved() int64
}

AnalyticsTracker interface for tracking data.

type CompressRequest

type CompressRequest struct {
	Content string `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"`
	Mode    string `protobuf:"bytes,2,opt,name=mode,proto3" json:"mode,omitempty"`
	Budget  int32  `protobuf:"varint,3,opt,name=budget,proto3" json:"budget,omitempty"`
}

CompressRequest represents a compression request.

type CompressResponse

type CompressResponse struct {
	Compressed       string  `protobuf:"bytes,1,opt,name=compressed,proto3" json:"compressed,omitempty"`
	OriginalTokens   int32   `protobuf:"varint,2,opt,name=original_tokens,json=originalTokens,proto3" json:"original_tokens,omitempty"`
	CompressedTokens int32   `protobuf:"varint,3,opt,name=compressed_tokens,json=compressedTokens,proto3" json:"compressed_tokens,omitempty"`
	SavedTokens      int32   `protobuf:"varint,4,opt,name=saved_tokens,json=savedTokens,proto3" json:"saved_tokens,omitempty"`
	ReductionPercent float64 `protobuf:"fixed64,5,opt,name=reduction_percent,json=reductionPercent,proto3" json:"reduction_percent,omitempty"`
}

CompressResponse represents a compression response.

type CompressionRatioRequest

type CompressionRatioRequest struct{}

CompressionRatioRequest requests compression stats

type CompressionRatioResponse

type CompressionRatioResponse struct {
	InputTokens       int64
	OutputTokens      int64
	TokensSaved       int64
	Ratio             float64
	SavingsPercentage float64
	GeneratedAt       int64
}

CompressionRatioResponse contains compression stats

type CompressionService

type CompressionService struct {
	UnimplementedCompressionServiceServer
}

CompressionService implements the gRPC compression service.

func (*CompressionService) Compress

Compress handles single compression requests.

func (*CompressionService) GetStats

GetStats returns service statistics.

func (*CompressionService) StreamCompress

StreamCompress handles streaming compression.

type CompressionServiceServer

type CompressionServiceServer interface {
	Compress(context.Context, *CompressRequest) (*CompressResponse, error)
	StreamCompress(CompressionService_StreamCompressServer) error
	GetStats(context.Context, *StatsRequest) (*StatsResponse, error)
}

CompressionServiceServer is the server API.

type CompressionService_StreamCompressServer

type CompressionService_StreamCompressServer interface {
	Recv() (*CompressRequest, error)
	Send(*CompressResponse) error
	grpc.ServerStream
}

CompressionService_StreamCompressServer is the server API for streaming.

type CostAnalysisRequest

type CostAnalysisRequest struct {
	ModelName string
}

CostAnalysisRequest requests cost estimation

type CostAnalysisResponse

type CostAnalysisResponse struct {
	TotalTokensSaved  int64
	CostPerMillion    float64
	Currency          string
	EstimatedSavings  float64
	MonthlyProjection float64
	YearlyProjection  float64
	ModelName         string
	GeneratedAt       int64
}

CostAnalysisResponse contains cost analysis

type DailyRecord

type DailyRecord struct {
	Date     string
	Saved    int
	Input    int
	Output   int
	Commands int
}

DailyRecord represents daily tracking data.

type DailyUsage

type DailyUsage struct {
	Date        string
	TokensSaved int64
	Commands    int64
}

DailyUsage represents one day of usage

type ExportFormat

type ExportFormat int32

ExportFormat defines export format type

const (
	ExportFormat_JSON ExportFormat = iota
	ExportFormat_CSV
	ExportFormat_PROTO
)

Export format constants

type ExportRequest

type ExportRequest struct {
	Format ExportFormat
}

ExportRequest requests data export

type ExportResponse

type ExportResponse struct {
	Data        []byte
	Format      string
	GeneratedAt int64
}

ExportResponse contains exported data

type LayerInfo

type LayerInfo struct {
	Name        string
	Description string
	Enabled     bool
}

LayerInfo represents layer information.

type LayerMetrics

type LayerMetrics struct {
	LayerName   string
	Invocations int64
	TokensSaved int64
	AvgNanos    int64
}

LayerMetrics represents metrics for one layer

type LayerPerformanceRequest

type LayerPerformanceRequest struct{}

LayerPerformanceRequest requests layer metrics

type LayerPerformanceResponse

type LayerPerformanceResponse struct {
	Layers      []*LayerMetrics
	GeneratedAt int64
}

LayerPerformanceResponse contains layer metrics

type LayerRegistry

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

LayerRegistry manages compression layers.

type LayerStat

type LayerStat struct {
	Name        string
	Invocations int64
	TokensSaved int64
	AvgTime     time.Duration
}

LayerStat represents layer statistics.

type RealtimeEvent

type RealtimeEvent struct {
	Timestamp        int64
	TotalTokensSaved int64
	LayerMetrics     map[string]*LayerMetrics
}

RealtimeEvent represents a realtime analytics event

type RealtimeStreamRequest

type RealtimeStreamRequest struct {
	IntervalSeconds int32
}

RealtimeStreamRequest configures realtime stream

type Server

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

Server provides gRPC server functionality.

func NewServer

func NewServer(port int) *Server

NewServer creates a new gRPC server.

func (*Server) Port

func (s *Server) Port() int

Port returns the actual port.

func (*Server) Start

func (s *Server) Start() error

Start starts the gRPC server.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the gRPC server.

type StatsRequest

type StatsRequest struct{}

StatsRequest represents a stats request.

type StatsResponse

type StatsResponse struct {
	TotalRequests    int64 `protobuf:"varint,1,opt,name=total_requests,json=totalRequests,proto3" json:"total_requests,omitempty"`
	TotalTokensSaved int64 `protobuf:"varint,2,opt,name=total_tokens_saved,json=totalTokensSaved,proto3" json:"total_tokens_saved,omitempty"`
}

StatsResponse represents stats response.

type UnimplementedCompressionServiceServer

type UnimplementedCompressionServiceServer struct{}

UnimplementedCompressionServiceServer must be embedded for forward compatibility.

func (UnimplementedCompressionServiceServer) Compress

func (UnimplementedCompressionServiceServer) GetStats

func (UnimplementedCompressionServiceServer) StreamCompress

type UsageReportRequest

type UsageReportRequest struct {
	Days int32
}

UsageReportRequest requests usage data

type UsageReportResponse

type UsageReportResponse struct {
	PeriodDays       int32
	TotalTokensSaved int64
	TotalCommands    int64
	DailyData        []*DailyUsage
	GeneratedAt      int64
}

UsageReportResponse contains usage analytics

Jump to

Keyboard shortcuts

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