Documentation
¶
Overview ¶
Package api wires together the HTTP router, middleware, and handlers.
Index ¶
- type DocumentStore
- type EvalExporter
- type EvalMetricsLister
- type FeedbackRecorder
- type FeedbackRequest
- type FeedbackResponse
- type IngestFileChunkWriter
- type IngestFileEmbedder
- type IngestFileResponse
- type IngestFileUpserter
- type IngestMessagesRequest
- type IngestMessagesResponse
- type IngestMessagesUpserter
- type IngestRecordingResponse
- type IngestRecordingUpserter
- type RecentItemsQuerier
- type ReindexRecommender
- type ReindexStateRecorder
- type Server
- func (s *Server) Handler() http.Handler
- func (s *Server) WithEvalMetrics(em EvalMetricsLister) *Server
- func (s *Server) WithIngestFile(upserter IngestFileUpserter, chunks IngestFileChunkWriter, ...) *Server
- func (s *Server) WithIngestMessages(upserter IngestMessagesUpserter, chunks IngestFileChunkWriter, ...) *Server
- func (s *Server) WithIngestRecording(upserter IngestRecordingUpserter, recordingDir string, maxFileBytes int64, ...) *Server
- func (s *Server) WithReindexCheck(rc ReindexRecommender) *Server
- func (s *Server) WithReindexState(rs ReindexStateRecorder) *Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DocumentStore ¶
type DocumentStore interface {
GetByID(ctx context.Context, id uuid.UUID) (*model.Document, error)
ListBySource(ctx context.Context, src model.SourceType, limit, offset int) ([]*model.Document, error)
ListRecent(ctx context.Context, includeSrc model.SourceType, excludeSrcs []model.SourceType, limit, offset int) ([]*model.Document, error)
CountBySource(ctx context.Context) (map[string]int, error)
QueryBaselineStats(ctx context.Context) (*store.BaselineStats, error)
}
DocumentStore is the subset of store.DocumentStore used by the API.
type EvalExporter ¶
EvalExporter is the subset of store.EvalStore used by the eval export handler. Defined as an interface so tests can inject a stub without a real database.
type EvalMetricsLister ¶
type EvalMetricsLister interface {
List(ctx context.Context, limit int) ([]store.EvalMetricsRecord, error)
}
EvalMetricsLister is the subset of store.EvalMetricsStore used by the eval metrics handler. Defined as an interface so tests can inject a stub.
type FeedbackRecorder ¶
FeedbackRecorder is the subset of store.FeedbackStore used by the feedback handler. Defined as an interface so tests can inject a stub without a real database.
type FeedbackRequest ¶
type FeedbackRequest struct {
Query *string `json:"query,omitempty"`
DocumentID *string `json:"document_id,omitempty"`
ChunkID *int64 `json:"chunk_id,omitempty"`
Source string `json:"source"`
SessionID *string `json:"session_id,omitempty"`
UserID *string `json:"user_id,omitempty"`
Thumbs int16 `json:"thumbs"`
Comment *string `json:"comment,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
FeedbackRequest is the JSON body accepted by POST /api/v1/feedback.
type FeedbackResponse ¶
type FeedbackResponse struct {
ID int64 `json:"id"`
}
FeedbackResponse is returned on successful feedback creation.
type IngestFileChunkWriter ¶ added in v0.17.0
type IngestFileChunkWriter interface {
ReplaceDocument(ctx context.Context, documentID uuid.UUID, chunks []store.Chunk) error
ListByDocument(ctx context.Context, documentID uuid.UUID) ([]store.Chunk, error)
UpdateChunkEmbeddings(ctx context.Context, embeddings []store.ChunkEmbedding) error
}
IngestFileChunkWriter is the chunk persistence interface required by the ingest-file handler. *store.ChunkStore satisfies this interface.
type IngestFileEmbedder ¶ added in v0.17.0
type IngestFileEmbedder interface {
Enabled() bool
EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
}
IngestFileEmbedder is the embedding interface required by the ingest-file handler. The search.EmbeddingEngine satisfies this interface.
type IngestFileResponse ¶ added in v0.17.0
type IngestFileResponse struct {
DocumentID string `json:"document_id"`
Accepted bool `json:"accepted"`
}
IngestFileResponse is the JSON body returned on a successful upload.
type IngestFileUpserter ¶ added in v0.17.0
IngestFileUpserter is the document persistence interface required by the ingest-file handler. *store.DocumentStore satisfies this interface.
type IngestMessagesRequest ¶ added in v0.18.0
type IngestMessagesRequest struct {
SMS []ingestSMSRecord `json:"sms"`
Calls []ingestCallRecord `json:"calls"`
}
IngestMessagesRequest is the JSON body accepted by POST /api/v1/ingest/messages.
type IngestMessagesResponse ¶ added in v0.18.0
type IngestMessagesResponse struct {
Accepted int `json:"accepted"`
Skipped int `json:"skipped"`
Errors []string `json:"errors"`
}
IngestMessagesResponse is the JSON body returned on a successful request.
type IngestMessagesUpserter ¶ added in v0.18.0
IngestMessagesUpserter is the document persistence interface required by the ingest-messages handler. *store.DocumentStore satisfies this interface.
Note: this is intentionally identical to IngestFileUpserter so a single concrete store implementation can satisfy both without wrapping.
type IngestRecordingResponse ¶ added in v0.18.0
type IngestRecordingResponse struct {
Accepted bool `json:"accepted"`
Skipped bool `json:"skipped"`
DocumentID string `json:"document_id,omitempty"`
}
IngestRecordingResponse is the JSON body returned on a successful request.
type IngestRecordingUpserter ¶ added in v0.18.0
IngestRecordingUpserter is the document persistence interface required by the ingest-recording handler. *store.DocumentStore satisfies this interface.
type RecentItemsQuerier ¶ added in v0.19.0
type RecentItemsQuerier interface {
ListRecentByKind(ctx context.Context, kind store.RecentKind, limit int) ([]store.RecentItem, error)
CountByKind(ctx context.Context, kind store.RecentKind) (int, error)
}
RecentItemsQuerier is the store interface required by recentDocumentsHandler. It combines the paginated list query and the total-count query so the handler can report both the current page size and the true DB total in one response.
type ReindexRecommender ¶
type ReindexRecommender interface {
Check(ctx context.Context) (search.ReindexRecommendation, error)
}
ReindexRecommender is the subset of search.ReindexChecker used by the reindex check handler. Defined as an interface so tests can inject a stub.
type ReindexStateRecorder ¶
type ReindexStateRecorder interface {
Save(ctx context.Context, state store.ReindexState) error
}
ReindexStateRecorder is the subset of store.ReindexStateStore used by the reindex handler. Defined as an interface so tests can inject a stub.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the dependencies needed by all handlers.
func NewServer ¶
func NewServer( docs DocumentStore, svc *search.Service, feedback FeedbackRecorder, eval EvalExporter, llmClient llm.Completer, filesystemPath string, apiKey string, ) *Server
NewServer creates a Server with the provided dependencies.
func (*Server) Handler ¶
Handler returns the root http.Handler for the application. It is safe to call from multiple goroutines: the underlying router is built exactly once via sync.Once and the result is reused for every subsequent call.
func (*Server) WithEvalMetrics ¶
func (s *Server) WithEvalMetrics(em EvalMetricsLister) *Server
WithEvalMetrics attaches an EvalMetricsLister to the server so that the GET /api/v1/eval/metrics route is registered. Returns s for method chaining.
NOTE: WithEvalMetrics must be called before the first call to Handler(), because the chi router is built exactly once via sync.Once.
func (*Server) WithIngestFile ¶ added in v0.17.0
func (s *Server) WithIngestFile( upserter IngestFileUpserter, chunks IngestFileChunkWriter, embed IngestFileEmbedder, maxFileBytes int64, ) *Server
WithIngestFile attaches the dependencies required by POST /api/v1/ingest/file and enables the route.
maxFileBytes is the per-upload size cap in bytes; 0 uses the package default (100 MiB). Pass cfg.IngestMaxFileBytes here.
Must be called before the first call to Handler().
func (*Server) WithIngestMessages ¶ added in v0.18.0
func (s *Server) WithIngestMessages( upserter IngestMessagesUpserter, chunks IngestFileChunkWriter, embed IngestFileEmbedder, maxBatchMessages int, cutover time.Time, ) *Server
WithIngestMessages attaches the dependencies required by POST /api/v1/ingest/messages and enables the route.
maxBatchMessages caps the total number of SMS + call records accepted in a single request; 0 uses the package default (5000). Pass cfg.IngestMaxBatchMessages here.
cutover is the optional floor time inherited from cfg.CollectorCutover: records whose OccurredAt is before this time are silently skipped. Zero time.Time{} disables the floor.
Must be called before the first call to Handler().
func (*Server) WithIngestRecording ¶ added in v0.18.0
func (s *Server) WithIngestRecording( upserter IngestRecordingUpserter, recordingDir string, maxFileBytes int64, cutover time.Time, ) *Server
WithIngestRecording attaches the dependencies required by POST /api/v1/ingest/recording and enables the route.
recordingDir is the directory where uploaded audio files are written; it must be non-empty for the route to be active. Corresponds to cfg.IngestRecordingDir.
maxFileBytes is the per-upload size cap (bytes); 0 uses the package default (100 MiB). Pass cfg.IngestMaxFileBytes here.
cutover is the optional floor time from cfg.CollectorCutover: recordings whose parsed timestamp is before this value are silently skipped (accepted=false, skipped=true). Zero time.Time{} disables the floor.
Must be called before the first call to Handler().
func (*Server) WithReindexCheck ¶
func (s *Server) WithReindexCheck(rc ReindexRecommender) *Server
WithReindexCheck attaches a ReindexRecommender to the server so that the GET /api/v1/reindex/check route is registered. Returns s for method chaining.
NOTE: WithReindexCheck must be called before the first call to Handler(), because the chi router is built exactly once via sync.Once.
func (*Server) WithReindexState ¶
func (s *Server) WithReindexState(rs ReindexStateRecorder) *Server
WithReindexState attaches a ReindexStateRecorder to the server so that the /api/v1/reindex route is registered. Returns s for method chaining.
NOTE: WithReindexState must be called before the first call to Handler(), because the chi router is built exactly once via sync.Once.