Documentation
¶
Overview ¶
Package http provides HTTP server functionality for contextd.
Package http provides HTTP API with metrics instrumentation.
Package http provides HTTP API for contextd.
Package http provides HTTP API for contextd.
Index ¶
- Constants
- func CountFromCollections(ctx context.Context, store vectorstore.Store) (checkpoints int, memories int)
- type CompressionStatus
- type Config
- type ContextStatus
- type HTTPMetrics
- type HealthResponse
- type MemoryStatus
- type MetadataHealthStatus
- type ScrubRequest
- type ScrubResponse
- type Server
- type StatusCounts
- type StatusResponse
- type ThresholdRequest
- type ThresholdResponse
Examples ¶
Constants ¶
const ( // CheckpointNameMaxLength is the UI display limit for checkpoint names. CheckpointNameMaxLength = 50 // CheckpointNameTruncationSuffix is added when names are truncated. CheckpointNameTruncationSuffix = "..." // MaxSummaryLength is the maximum length for summary fields. MaxSummaryLength = 10000 // MaxContextLength is the maximum length for context fields. MaxContextLength = 50000 // MinThresholdPercent is the minimum valid threshold percentage. MinThresholdPercent = 1 // MaxThresholdPercent is the maximum valid threshold percentage. MaxThresholdPercent = 100 )
Variables ¶
This section is empty.
Functions ¶
func CountFromCollections ¶ added in v0.3.0
func CountFromCollections(ctx context.Context, store vectorstore.Store) (checkpoints int, memories int)
CountFromCollections counts checkpoints and memories from vector store collections.
Collection names follow tenant naming conventions:
- org_checkpoints, org_memories
- {team}_checkpoints, {team}_memories
- {team}_{project}_checkpoints, {team}_{project}_memories
Returns (-1, -1) if:
- store is nil
- listing collections fails
- collections list is empty (chromem lazy loading case)
Otherwise returns the sum of point counts for matching collections.
Types ¶
type CompressionStatus ¶ added in v0.3.0
type CompressionStatus struct {
LastRatio float64 `json:"last_ratio"`
LastQuality float64 `json:"last_quality"`
OperationsTotal int64 `json:"operations_total"`
}
CompressionStatus contains compression metrics.
type Config ¶
type Config struct {
Host string
Port int
Version string
HealthChecker *vectorstore.MetadataHealthChecker // Optional metadata health checker
}
Config holds HTTP server configuration.
type ContextStatus ¶ added in v0.3.0
type ContextStatus struct {
UsagePercent int `json:"usage_percent"`
ThresholdWarning bool `json:"threshold_warning"`
}
ContextStatus contains context usage information.
type HTTPMetrics ¶ added in v0.4.0
type HTTPMetrics struct {
// contains filtered or unexported fields
}
HTTPMetrics holds all HTTP-related metrics.
func NewHTTPMetrics ¶ added in v0.4.0
func NewHTTPMetrics(logger *zap.Logger) *HTTPMetrics
NewHTTPMetrics creates a new HTTPMetrics instance.
func (*HTTPMetrics) MetricsMiddleware ¶ added in v0.4.0
func (m *HTTPMetrics) MetricsMiddleware() echo.MiddlewareFunc
MetricsMiddleware returns an Echo middleware that records HTTP metrics.
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"`
Metadata *MetadataHealthStatus `json:"metadata,omitempty"` // Optional metadata health
}
HealthResponse is the response body for GET /health.
type MemoryStatus ¶ added in v0.3.0
type MemoryStatus struct {
LastConfidence float64 `json:"last_confidence"`
}
MemoryStatus contains memory/reasoning bank metrics.
type MetadataHealthStatus ¶ added in v0.4.0
type MetadataHealthStatus struct {
Status string `json:"status"` // "healthy" or "degraded"
HealthyCount int `json:"healthy_count"` // Number of healthy collections
CorruptCount int `json:"corrupt_count"` // Number of corrupt collections
EmptyCount int `json:"empty_count"` // Number of empty collections
Total int `json:"total"` // Total collections
CorruptHashes []string `json:"corrupt_hashes"` // List of corrupt collection hashes
}
MetadataHealthStatus contains metadata integrity health information.
type ScrubRequest ¶
type ScrubRequest struct {
Content string `json:"content"`
}
ScrubRequest is the request body for POST /api/v1/scrub.
type ScrubResponse ¶
type ScrubResponse struct {
Content string `json:"content"`
FindingsCount int `json:"findings_count"`
}
ScrubResponse is the response body for POST /api/v1/scrub.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides HTTP endpoints for contextd.
Example ¶
ExampleServer demonstrates how to create and start the HTTP server.
package main
import (
"context"
"fmt"
"time"
httpserver "github.com/fyrsmithlabs/contextd/internal/http"
"github.com/fyrsmithlabs/contextd/internal/secrets"
"github.com/fyrsmithlabs/contextd/internal/services"
"go.uber.org/zap"
)
func main() {
// Create a scrubber with default configuration
scrubber, err := secrets.New(nil)
if err != nil {
panic(err)
}
// Create a services registry with minimal configuration
// In a real application, you would initialize all services
registry := services.NewRegistry(services.Options{
Scrubber: scrubber,
// Other services would be initialized here
})
// Create logger
logger, _ := zap.NewProduction()
defer func() { _ = logger.Sync() }()
// Configure the server
cfg := &httpserver.Config{
Host: "localhost",
Port: 9090,
}
// Create the server
server, err := httpserver.NewServer(registry, logger, cfg)
if err != nil {
panic(err)
}
// Start server in background
go func() {
if err := server.Start(); err != nil {
logger.Error("server error", zap.Error(err))
}
}()
// Give server time to start
time.Sleep(100 * time.Millisecond)
// Graceful shutdown
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
logger.Error("shutdown error", zap.Error(err))
}
fmt.Println("Server started and stopped successfully")
}
Output: Server started and stopped successfully
type StatusCounts ¶ added in v0.3.0
StatusCounts contains count information for various resources.
type StatusResponse ¶ added in v0.3.0
type StatusResponse struct {
Status string `json:"status"`
Version string `json:"version,omitempty"`
Services map[string]string `json:"services"`
Counts StatusCounts `json:"counts"`
Context *ContextStatus `json:"context,omitempty"`
Compression *CompressionStatus `json:"compression,omitempty"`
Memory *MemoryStatus `json:"memory,omitempty"`
}
StatusResponse is the response body for GET /api/v1/status.
type ThresholdRequest ¶
type ThresholdRequest struct {
ProjectID string `json:"project_id"`
SessionID string `json:"session_id"`
Percent int `json:"percent"`
Summary string `json:"summary,omitempty"` // Brief summary of session work (recommended)
Context string `json:"context,omitempty"` // Additional context for resumption
ProjectPath string `json:"project_path,omitempty"` // Full project path (defaults to project_id)
}
ThresholdRequest is the request body for POST /api/v1/threshold.
type ThresholdResponse ¶
type ThresholdResponse struct {
CheckpointID string `json:"checkpoint_id"`
Message string `json:"message"`
}
ThresholdResponse is the response body for POST /api/v1/threshold.