Documentation
¶
Index ¶
- Constants
- func AdminAuthMiddleware(adminKey string, logger *slog.Logger) func(http.Handler) http.Handlerdeprecated
- type AdminError
- type AdminEvent
- type AdminHealth
- type AdminServer
- type AdminServerOptions
- type AdminSession
- type AdminSessionStats
- type AuditHandler
- type BatchStopFailed
- type BatchStopRequest
- type BatchStopResponse
- type ConfigHandler
- type ConfigResponse
- type DrainRequest
- type DrainResponse
- type ErrorCode
- type ErrorDetail
- type ErrorResponse
- type EventBuffer
- type EventsResponse
- type HealthHandler
- type SessionHandler
- func (h *SessionHandler) BatchStopSessions(w http.ResponseWriter, r *http.Request)
- func (h *SessionHandler) GetSession(w http.ResponseWriter, r *http.Request)
- func (h *SessionHandler) ListSessions(w http.ResponseWriter, r *http.Request)
- func (h *SessionHandler) StopSession(w http.ResponseWriter, r *http.Request)
- type SessionPoolInterface
- type SessionsResponse
- type StopRequest
- type StopResponse
- type SubsystemHealth
- type ToolsResponse
- type TranscriptMsg
- type TranscriptResponse
Constants ¶
const ( ErrCodeAuthFailed = adminapi.ErrCodeAuthFailed ErrCodeForbidden = adminapi.ErrCodeForbidden ErrCodeNotFound = adminapi.ErrCodeNotFound ErrCodeInvalidRequest = adminapi.ErrCodeInvalidRequest ErrCodeServerError = adminapi.ErrCodeServerError ErrCodeEngineNotInitialized = adminapi.ErrCodeEngineNotInitialized )
Error code constants re-exported from adminapi.
Variables ¶
This section is empty.
Functions ¶
func AdminAuthMiddleware
deprecated
AdminAuthMiddleware creates an HTTP middleware that validates the X-API-Key header. It uses constant-time comparison to prevent timing attacks. If adminKey is empty, authentication is bypassed (no auth required).
Deprecated: Use adminapi.AuthMiddleware directly with AuthModeAPIKey. This function is kept for backward compatibility.
Types ¶
type AdminError ¶
type AdminError = ErrorResponse
AdminError is an alias for the shared ErrorResponse.
func NewAdminError ¶
func NewAdminError(code ErrorCode, message string) AdminError
NewAdminError creates a new AdminError with the given code and message. Deprecated: Use adminapi.NewError directly.
func NewAdminErrorWithDetails ¶
func NewAdminErrorWithDetails(code ErrorCode, message string, details map[string]interface{}) AdminError
NewAdminErrorWithDetails creates a new AdminError with details. Deprecated: Use adminapi.NewErrorWithDetails directly.
type AdminEvent ¶
type AdminEvent struct {
EventID string `json:"event_id"`
Timestamp time.Time `json:"timestamp"`
Type string `json:"type"`
SessionID string `json:"session_id,omitempty"`
Actor string `json:"actor,omitempty"`
Payload map[string]interface{} `json:"payload,omitempty"`
}
AdminEvent represents an audit event in the ring buffer.
type AdminHealth ¶
type AdminHealth struct {
Status string `json:"status"`
Version string `json:"version"`
Uptime string `json:"uptime"`
Subsystems map[string]SubsystemHealth `json:"subsystems"`
}
AdminHealth represents the overall system health.
type AdminServer ¶
type AdminServer struct {
// contains filtered or unexported fields
}
AdminServer is the main admin API server that combines all handlers.
func NewAdminServer ¶
func NewAdminServer(opts AdminServerOptions) *AdminServer
NewAdminServer creates a new admin server with all handlers registered.
func (*AdminServer) GetEventBuffer ¶
func (s *AdminServer) GetEventBuffer() *EventBuffer
GetEventBuffer returns the event buffer for event recording.
func (*AdminServer) GetHealthHandler ¶
func (s *AdminServer) GetHealthHandler() *HealthHandler
GetHealthHandler returns the health handler for drain integration.
func (*AdminServer) ServeHTTP ¶
func (s *AdminServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
type AdminServerOptions ¶
type AdminServerOptions struct {
Engine *engine.Engine
AdminKey string
Logger *slog.Logger
EventBufferSize int
}
AdminServerOptions contains options for creating an AdminServer.
type AdminSession ¶
type AdminSession struct {
SessionID string `json:"session_id"`
Status string `json:"status"`
Platform string `json:"platform"`
CreatedAt time.Time `json:"created_at"`
LastActiveAt time.Time `json:"last_active_at"`
Tags map[string]string `json:"tags,omitempty"`
}
AdminSession represents a session in the admin API. Status is mapped from engine.SessionStatus:
- SessionStatusStarting -> "starting"
- SessionStatusReady -> "idle"
- SessionStatusBusy -> "running"
- SessionStatusDead -> "dead"
func MapSessionToAdminSession ¶
func MapSessionToAdminSession(s *intengine.Session) AdminSession
MapSessionToAdminSession converts an internal engine.Session to AdminSession.
type AdminSessionStats ¶
type AdminSessionStats struct {
SessionID string `json:"session_id"`
TotalDurationMs int64 `json:"total_duration_ms"`
ThinkingDurationMs int64 `json:"thinking_duration_ms"`
ToolDurationMs int64 `json:"tool_duration_ms"`
GenerationDurationMs int64 `json:"generation_duration_ms"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
CacheReadTokens int64 `json:"cache_read_tokens"`
CacheWriteTokens int64 `json:"cache_write_tokens"`
ToolCallCount int64 `json:"tool_call_count"`
ToolsUsed []string `json:"tools_used,omitempty"`
FilesModified int64 `json:"files_modified"`
FilePaths []string `json:"file_paths,omitempty"`
ErrorCount int64 `json:"error_count"`
}
AdminSessionStats represents execution statistics aligned with engine.SessionStats.
func MapSessionStatsToAdminStats ¶
func MapSessionStatsToAdminStats(stats *engine.SessionStats) AdminSessionStats
MapSessionStatsToAdminStats converts engine.SessionStats to AdminSessionStats.
type AuditHandler ¶
type AuditHandler struct {
// contains filtered or unexported fields
}
AuditHandler handles audit and history endpoints.
func NewAuditHandler ¶
func NewAuditHandler(eventBuffer *EventBuffer, sessionPool interface { GetSession(sessionID string) (*intengine.Session, bool) }) *AuditHandler
NewAuditHandler creates a new audit handler.
func (*AuditHandler) PushEvent ¶
func (h *AuditHandler) PushEvent(event AdminEvent)
PushEvent is a helper to add an event to the buffer.
type BatchStopFailed ¶
BatchStopFailed represents a failed session stop.
type BatchStopRequest ¶
type BatchStopRequest struct {
SessionIDs []string `json:"session_ids"`
Reason string `json:"reason"`
}
BatchStopRequest is the request body for batch session stop.
type BatchStopResponse ¶
type BatchStopResponse struct {
Stopped []string `json:"stopped"`
NotFound []string `json:"not_found"`
Failed []BatchStopFailed `json:"failed"`
}
BatchStopResponse is the response for batch session stop.
type ConfigHandler ¶
type ConfigHandler struct {
// contains filtered or unexported fields
}
ConfigHandler handles configuration endpoints.
func NewConfigHandler ¶
func NewConfigHandler(eng *engine.Engine) *ConfigHandler
NewConfigHandler creates a new config handler.
type ConfigResponse ¶
type ConfigResponse struct {
Config any `json:"config"`
}
ConfigResponse is the response for config endpoint.
type DrainRequest ¶
type DrainRequest struct {
Message string `json:"message"`
}
DrainRequest is the request body for entering drain mode.
type DrainResponse ¶
type DrainResponse struct {
Status string `json:"status"`
ActiveSessions int `json:"active_sessions,omitempty"`
Message string `json:"message,omitempty"`
}
DrainResponse is the response for drain mode operations.
type ErrorDetail ¶
type ErrorDetail = adminapi.ErrorDetail
Re-export shared error types from adminapi for convenience.
type ErrorResponse ¶
type ErrorResponse = adminapi.ErrorResponse
Re-export shared error types from adminapi for convenience.
type EventBuffer ¶
type EventBuffer struct {
// contains filtered or unexported fields
}
EventBuffer is a thread-safe ring buffer for audit events. It stores the last maxSize events in memory for fast access.
func NewEventBuffer ¶
func NewEventBuffer(maxSize int) *EventBuffer
NewEventBuffer creates a new event buffer with the given maximum size.
func (*EventBuffer) GetEvents ¶
func (b *EventBuffer) GetEvents() []AdminEvent
GetEvents returns all events in chronological order (oldest first).
func (*EventBuffer) GetEventsPaginated ¶
func (b *EventBuffer) GetEventsPaginated(limit, offset int) ([]AdminEvent, int64)
GetEventsPaginated returns events with pagination support.
func (*EventBuffer) MaxSize ¶
func (b *EventBuffer) MaxSize() int
MaxSize returns the maximum capacity of the buffer.
func (*EventBuffer) Push ¶
func (b *EventBuffer) Push(event AdminEvent)
Push adds a new event to the buffer. If the buffer is full, the oldest event is overwritten.
func (*EventBuffer) Size ¶
func (b *EventBuffer) Size() int
Size returns the current number of events in the buffer.
type EventsResponse ¶
type EventsResponse struct {
Events []AdminEvent `json:"events"`
NextCursor string `json:"next_cursor,omitempty"`
Total int64 `json:"total"`
}
EventsResponse is the response for listing events.
type HealthHandler ¶
type HealthHandler struct {
// contains filtered or unexported fields
}
HealthHandler handles health, metrics, and drain endpoints.
func NewHealthHandler ¶
NewHealthHandler creates a new health handler.
func (*HealthHandler) GetDrainMessage ¶
func (h *HealthHandler) GetDrainMessage() string
GetDrainMessage returns the drain message.
func (*HealthHandler) IsDraining ¶
func (h *HealthHandler) IsDraining() bool
IsDraining returns true if the service is in drain mode.
type SessionHandler ¶
type SessionHandler struct {
// contains filtered or unexported fields
}
SessionHandler handles session management endpoints.
func NewSessionHandler ¶
func NewSessionHandler(pool SessionPoolInterface) *SessionHandler
NewSessionHandler creates a new session handler.
func (*SessionHandler) BatchStopSessions ¶
func (h *SessionHandler) BatchStopSessions(w http.ResponseWriter, r *http.Request)
BatchStopSessions handles POST /api/v1/sessions/batch-stop
func (*SessionHandler) GetSession ¶
func (h *SessionHandler) GetSession(w http.ResponseWriter, r *http.Request)
GetSession handles GET /api/v1/sessions/:id
func (*SessionHandler) ListSessions ¶
func (h *SessionHandler) ListSessions(w http.ResponseWriter, r *http.Request)
ListSessions handles GET /api/v1/sessions
func (*SessionHandler) StopSession ¶
func (h *SessionHandler) StopSession(w http.ResponseWriter, r *http.Request)
StopSession handles POST /api/v1/sessions/:id/stop
type SessionPoolInterface ¶
type SessionPoolInterface interface {
ListActiveSessions() []*intengine.Session
GetSession(sessionID string) (*intengine.Session, bool)
TerminateSession(sessionID string) error
}
SessionPoolInterface defines the interface for session pool operations needed by admin handlers.
type SessionsResponse ¶
type SessionsResponse struct {
Sessions []AdminSession `json:"sessions"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
SessionsResponse is the response for listing sessions.
type StopRequest ¶
type StopRequest struct {
Reason string `json:"reason"`
}
StopRequest is the request body for single session stop.
type StopResponse ¶
type StopResponse struct {
SessionID string `json:"session_id"`
Status string `json:"status"`
Message string `json:"message"`
}
StopResponse is the response for single session stop.
type SubsystemHealth ¶
type SubsystemHealth struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
Latency string `json:"latency,omitempty"`
}
SubsystemHealth represents the health of a single subsystem.
type ToolsResponse ¶
ToolsResponse is the response for tools list endpoints.
type TranscriptMsg ¶
type TranscriptMsg struct {
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Content string `json:"content"`
}
TranscriptMsg represents a single message in a transcript.
type TranscriptResponse ¶
type TranscriptResponse struct {
SessionID string `json:"session_id"`
Messages []TranscriptMsg `json:"messages"`
}
TranscriptResponse is the response for session transcript.