Documentation
¶
Overview ¶
Package api provides the REST API for Langley.
Index ¶
- type AnomalyResponse
- type CSVExporter
- func (e *CSVExporter) ContentType() string
- func (e *CSVExporter) FileExtension() string
- func (e *CSVExporter) WriteFlow(w io.Writer, flow *store.Flow, includeBodies bool) error
- func (e *CSVExporter) WriteFooter(w io.Writer, rowCount int, truncatedBodies int) error
- func (e *CSVExporter) WriteHeader(w io.Writer) error
- type CheckpointResponse
- type CostPeriodResponse
- type EventResponse
- type ExportConfig
- type ExportFlowFull
- type ExportFlowSummary
- type ExportFormat
- type FlowDetail
- type FlowExporter
- type FlowSummary
- type HealthResponse
- type JSONExporter
- func (e *JSONExporter) ContentType() string
- func (e *JSONExporter) FileExtension() string
- func (e *JSONExporter) WriteFlow(w io.Writer, flow *store.Flow, includeBodies bool) error
- func (e *JSONExporter) WriteFooter(w io.Writer, rowCount int, truncatedBodies int) error
- func (e *JSONExporter) WriteHeader(w io.Writer) error
- type NDJSONExporter
- func (e *NDJSONExporter) ContentType() string
- func (e *NDJSONExporter) FileExtension() string
- func (e *NDJSONExporter) WriteFlow(w io.Writer, flow *store.Flow, includeBodies bool) error
- func (e *NDJSONExporter) WriteFooter(w io.Writer, rowCount int, truncatedBodies int) error
- func (e *NDJSONExporter) WriteHeader(w io.Writer) error
- type OverallStatsResponse
- type RateLimiter
- type Server
- type ServerOption
- type SettingsResponse
- type SettingsUpdateRequest
- type StatsResponse
- type TaskSummaryResponse
- type ToolInvocationListResponse
- type ToolInvocationResponse
- type ToolStatsResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnomalyResponse ¶
type AnomalyResponse struct {
Type string `json:"type"`
FlowID string `json:"flow_id"`
TaskID *string `json:"task_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
Severity string `json:"severity"`
Description string `json:"description"`
Value float64 `json:"value"`
Threshold float64 `json:"threshold"`
}
AnomalyResponse is the API response for anomalies.
type CSVExporter ¶
type CSVExporter struct {
// contains filtered or unexported fields
}
CSVExporter exports flows as CSV (summary fields only).
func NewCSVExporter ¶
func NewCSVExporter() *CSVExporter
func (*CSVExporter) ContentType ¶
func (e *CSVExporter) ContentType() string
func (*CSVExporter) FileExtension ¶
func (e *CSVExporter) FileExtension() string
func (*CSVExporter) WriteFooter ¶
func (*CSVExporter) WriteHeader ¶
func (e *CSVExporter) WriteHeader(w io.Writer) error
type CheckpointResponse ¶
type CheckpointResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
WALSizeBefore int64 `json:"wal_size_before_bytes"`
WALSizeAfter int64 `json:"wal_size_after_bytes"`
PagesLog int `json:"pages_in_log"`
PagesCheckpointed int `json:"pages_checkpointed"`
Blocked bool `json:"was_blocked"`
Timestamp time.Time `json:"timestamp"`
}
CheckpointResponse is the API response for WAL checkpoint operations.
type CostPeriodResponse ¶
type CostPeriodResponse struct {
Period string `json:"period"`
FlowCount int `json:"flow_count"`
TotalCost float64 `json:"total_cost"`
TotalTokensIn int `json:"total_tokens_in"`
TotalTokensOut int `json:"total_tokens_out"`
}
CostPeriodResponse is the API response for cost breakdowns.
type EventResponse ¶
type EventResponse struct {
ID string `json:"id"`
Sequence int `json:"sequence"`
Timestamp time.Time `json:"timestamp"`
EventType string `json:"event_type"`
EventData map[string]interface{} `json:"event_data,omitempty"`
Priority string `json:"priority"`
}
EventResponse is the API response for an event.
type ExportConfig ¶
type ExportConfig struct {
Format ExportFormat
IncludeBodies bool
MaxRows int
}
ExportConfig holds export configuration parsed from query params.
func ParseExportConfig ¶
func ParseExportConfig(r *http.Request) ExportConfig
ParseExportConfig parses export configuration from request query params.
type ExportFlowFull ¶
type ExportFlowFull struct {
ExportFlowSummary
RequestBody *string `json:"request_body,omitempty"`
RequestBodyTruncated bool `json:"request_body_truncated,omitempty"`
ResponseBody *string `json:"response_body,omitempty"`
ResponseBodyTruncated bool `json:"response_body_truncated,omitempty"`
RequestHeaders map[string][]string `json:"request_headers,omitempty"`
ResponseHeaders map[string][]string `json:"response_headers,omitempty"`
}
ExportFlowFull extends ExportFlowSummary with body fields.
type ExportFlowSummary ¶
type ExportFlowSummary struct {
ID string `json:"id"`
Timestamp string `json:"timestamp"`
Host string `json:"host"`
Method string `json:"method"`
Path string `json:"path"`
StatusCode *int `json:"status_code"`
DurationMs *int64 `json:"duration_ms,omitempty"`
IsSSE bool `json:"is_sse"`
TaskID *string `json:"task_id,omitempty"`
TaskSource *string `json:"task_source,omitempty"`
Model *string `json:"model,omitempty"`
Provider string `json:"provider"`
InputTokens *int `json:"input_tokens,omitempty"`
OutputTokens *int `json:"output_tokens,omitempty"`
TotalCost *float64 `json:"total_cost,omitempty"`
FlowIntegrity string `json:"flow_integrity"`
}
ExportFlowSummary is the export format for flows (NDJSON streaming).
type ExportFormat ¶
type ExportFormat string
ExportFormat represents supported export formats.
const ( FormatNDJSON ExportFormat = "ndjson" FormatJSON ExportFormat = "json" FormatCSV ExportFormat = "csv" // MaxCSVRows limits CSV exports to prevent browser/Excel issues MaxCSVRows = 10000 // MaxJSONRows limits JSON exports to prevent OOM (JSON buffers all rows in memory) MaxJSONRows = 10000 )
type FlowDetail ¶
type FlowDetail struct {
FlowSummary
URL string `json:"url"`
StatusText *string `json:"status_text,omitempty"`
Provider string `json:"provider"`
FlowIntegrity string `json:"flow_integrity"`
EventsDroppedCount int `json:"events_dropped_count"`
RequestBody *string `json:"request_body,omitempty"`
RequestBodyTruncated bool `json:"request_body_truncated"`
ResponseBody *string `json:"response_body,omitempty"`
ResponseBodyTruncated bool `json:"response_body_truncated"`
RequestHeaders map[string][]string `json:"request_headers,omitempty"`
ResponseHeaders map[string][]string `json:"response_headers,omitempty"`
CacheCreationTokens *int `json:"cache_creation_tokens,omitempty"`
CacheReadTokens *int `json:"cache_read_tokens,omitempty"`
CostSource *string `json:"cost_source,omitempty"`
}
FlowDetail is the detailed view of a flow.
type FlowExporter ¶
type FlowExporter interface {
// ContentType returns the MIME type for this format.
ContentType() string
// FileExtension returns the file extension for downloads.
FileExtension() string
// WriteHeader writes any header/preamble needed.
WriteHeader(w io.Writer) error
// WriteFlow writes a single flow.
WriteFlow(w io.Writer, flow *store.Flow, includeBodies bool) error
WriteFooter(w io.Writer, rowCount int, truncatedBodies int) error
}
FlowExporter writes flows in a specific format.
func NewExporter ¶
func NewExporter(format ExportFormat) FlowExporter
NewExporter creates an exporter for the given format.
type FlowSummary ¶
type FlowSummary struct {
ID string `json:"id"`
Host string `json:"host"`
Method string `json:"method"`
Path string `json:"path"`
StatusCode *int `json:"status_code"`
IsSSE bool `json:"is_sse"`
Timestamp time.Time `json:"timestamp"`
DurationMs *int64 `json:"duration_ms,omitempty"`
TaskID *string `json:"task_id,omitempty"`
TaskSource *string `json:"task_source,omitempty"`
Model *string `json:"model,omitempty"`
InputTokens *int `json:"input_tokens,omitempty"`
OutputTokens *int `json:"output_tokens,omitempty"`
TotalCost *float64 `json:"total_cost,omitempty"`
}
FlowSummary is the summary view of a flow.
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"` // "ok", "degraded", "error"
Timestamp time.Time `json:"timestamp"`
Uptime string `json:"uptime"`
WALSizeBytes int64 `json:"wal_size_bytes"`
WALCheckpointed int64 `json:"wal_checkpointed_bytes"`
DropsLast24h int64 `json:"drops_last_24h"`
ActiveFlows int `json:"active_flows"` // Flows in last 5 minutes
TotalFlows int64 `json:"total_flows"`
DBSizeBytes int64 `json:"db_size_bytes"`
Warning string `json:"warning,omitempty"`
}
HealthResponse is the API response for health status.
type JSONExporter ¶
type JSONExporter struct {
// contains filtered or unexported fields
}
JSONExporter exports flows as a JSON array with metadata.
func NewJSONExporter ¶
func NewJSONExporter() *JSONExporter
func (*JSONExporter) ContentType ¶
func (e *JSONExporter) ContentType() string
func (*JSONExporter) FileExtension ¶
func (e *JSONExporter) FileExtension() string
func (*JSONExporter) WriteFooter ¶
func (*JSONExporter) WriteHeader ¶
func (e *JSONExporter) WriteHeader(w io.Writer) error
type NDJSONExporter ¶
type NDJSONExporter struct {
// contains filtered or unexported fields
}
NDJSONExporter exports flows as newline-delimited JSON.
func NewNDJSONExporter ¶
func NewNDJSONExporter() *NDJSONExporter
func (*NDJSONExporter) ContentType ¶
func (e *NDJSONExporter) ContentType() string
func (*NDJSONExporter) FileExtension ¶
func (e *NDJSONExporter) FileExtension() string
func (*NDJSONExporter) WriteFooter ¶
func (*NDJSONExporter) WriteHeader ¶
func (e *NDJSONExporter) WriteHeader(w io.Writer) error
type OverallStatsResponse ¶
type OverallStatsResponse struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
TotalFlows int `json:"total_flows"`
AllTimeFlows int `json:"all_time_flows"`
TotalCost float64 `json:"total_cost"`
TotalTokensIn int `json:"total_tokens_in"`
TotalTokensOut int `json:"total_tokens_out"`
TotalTasks int `json:"total_tasks"`
TotalToolCalls int `json:"total_tool_calls"`
AvgCostPerFlow float64 `json:"avg_cost_per_flow"`
AvgTokensPerFlow float64 `json:"avg_tokens_per_flow"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
}
OverallStatsResponse is the detailed stats response.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements a token bucket rate limiter per source IP. Provides burst capacity for legitimate traffic while preventing abuse.
func NewRateLimiter ¶
func NewRateLimiter(rate float64, burst int) *RateLimiter
NewRateLimiter creates a rate limiter with the given sustained rate and burst capacity. - rate: sustained requests per second (e.g., 20) - burst: maximum burst capacity (e.g., 100)
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(ip string) bool
Allow checks if a request from the given IP should be allowed. Returns true if allowed, false if rate limited.
func (*RateLimiter) Middleware ¶
func (rl *RateLimiter) Middleware(next http.Handler) http.Handler
Middleware returns an HTTP middleware that applies rate limiting. Returns 429 Too Many Requests when rate is exceeded.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the REST API server.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption configures the API server.
func WithConfigPath ¶
func WithConfigPath(path string) ServerOption
WithConfigPath sets the config file path for reload support.
func WithOnReload ¶
func WithOnReload(fn func(newToken string)) ServerOption
WithOnReload sets a callback to be called when config is reloaded. The callback receives the new auth token.
func WithPricingSource ¶
func WithPricingSource(source *pricing.Source) ServerOption
WithPricingSource sets the LiteLLM pricing source for cost calculations.
type SettingsResponse ¶
type SettingsResponse struct {
IdleGapMinutes int `json:"idle_gap_minutes"`
}
SettingsResponse is the API response for settings.
type SettingsUpdateRequest ¶
type SettingsUpdateRequest struct {
IdleGapMinutes *int `json:"idle_gap_minutes,omitempty"`
}
SettingsUpdateRequest is the request body for updating settings.
type StatsResponse ¶
StatsResponse is the API response for stats.
type TaskSummaryResponse ¶
type TaskSummaryResponse struct {
TaskID string `json:"task_id"`
FlowCount int `json:"flow_count"`
TotalTokensIn int `json:"total_tokens_in"`
TotalTokensOut int `json:"total_tokens_out"`
TotalCost float64 `json:"total_cost"`
FirstSeen time.Time `json:"first_seen"`
LastSeen time.Time `json:"last_seen"`
DurationMs int64 `json:"duration_ms"`
Models []string `json:"models,omitempty"`
ToolsUsed []string `json:"tools_used,omitempty"`
}
TaskSummaryResponse is the API response for task analytics.
type ToolInvocationListResponse ¶
type ToolInvocationListResponse struct {
Items []ToolInvocationResponse `json:"items"`
Total int `json:"total"`
}
ToolInvocationListResponse wraps a list of invocations with total count.
type ToolInvocationResponse ¶
type ToolInvocationResponse struct {
ID string `json:"id"`
FlowID string `json:"flow_id"`
TaskID *string `json:"task_id,omitempty"`
ToolUseID *string `json:"tool_use_id,omitempty"`
ToolName string `json:"tool_name"`
Timestamp time.Time `json:"timestamp"`
DurationMs *int64 `json:"duration_ms,omitempty"`
Success *bool `json:"success,omitempty"`
ErrorMessage *string `json:"error_message,omitempty"`
ToolInput *string `json:"tool_input,omitempty"`
ToolResult *string `json:"tool_result,omitempty"`
}
ToolInvocationResponse is the API response for a single tool invocation.
type ToolStatsResponse ¶
type ToolStatsResponse struct {
ToolName string `json:"tool_name"`
InvocationCount int `json:"invocation_count"`
SuccessCount int `json:"success_count"`
FailureCount int `json:"failure_count"`
SuccessRate float64 `json:"success_rate"`
TotalCost float64 `json:"total_cost"`
AvgDurationMs float64 `json:"avg_duration_ms"`
TotalTokensIn int `json:"total_tokens_in"`
TotalTokensOut int `json:"total_tokens_out"`
}
ToolStatsResponse is the API response for tool analytics.