Documentation
¶
Overview ¶
Package api provides the REST API for OpenBotStack runtime.
Package api provides the REST API for OpenBotStack runtime.
Index ¶
- Constants
- Variables
- func CorrelationIDFromContext(ctx context.Context) string
- func CorrelationMiddleware(next http.Handler) http.Handler
- type AuditExecutionStore
- type ChatHandler
- type ChatRequest
- type ChatResponse
- type ExecutionRecord
- type ExecutionStore
- type HistoryProvider
- type HistoryResponse
- type Message
- type Metrics
- type Router
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) SetAuthMiddleware(mw func(http.Handler) http.Handler)
- func (r *Router) SetExecutionStore(es ExecutionStore)
- func (r *Router) SetHistoryProvider(hp HistoryProvider)
- func (r *Router) SetSkillProvider(sp SkillProvider)
- type SSEEvent
- type SSEHandler
- type SSEStream
- type SkillProvider
- type SkillResponse
Constants ¶
const (
// CorrelationIDHeader is the HTTP header used to propagate correlation IDs.
CorrelationIDHeader = "X-Correlation-ID"
)
Variables ¶
var ( // ErrMissingTenantID is returned when tenant ID is missing. ErrMissingTenantID = errors.New("api: tenant_id is required") // ErrMissingMessage is returned when message is empty. ErrMissingMessage = errors.New("api: message is required") )
Functions ¶
func CorrelationIDFromContext ¶
CorrelationIDFromContext retrieves the correlation ID from the context.
func CorrelationMiddleware ¶
CorrelationMiddleware injects a correlation ID into each request context and adds it to the response headers. If an incoming request already carries the X-Correlation-ID header, that value is reused; otherwise a new UUID is generated.
Every log line emitted via slog during the request will include the correlation_id attribute when the returned handler is used.
Types ¶
type AuditExecutionStore ¶
type AuditExecutionStore struct {
// contains filtered or unexported fields
}
AuditExecutionStore adapts AuditLogger to ExecutionStore.
func NewAuditExecutionStore ¶
func NewAuditExecutionStore(logger audit.AuditLogger) *AuditExecutionStore
NewAuditExecutionStore creates an ExecutionStore backed by audit logs.
func (*AuditExecutionStore) QueryExecutions ¶
func (s *AuditExecutionStore) QueryExecutions(ctx context.Context, limit int) ([]ExecutionRecord, error)
QueryExecutions returns recent execution records from audit logs.
type ChatHandler ¶ added in v1.0.0
type ChatHandler struct {
// contains filtered or unexported fields
}
ChatHandler processes chat messages.
func NewChatHandler ¶ added in v1.0.0
func NewChatHandler() *ChatHandler
NewChatHandler creates a new chat handler.
func (*ChatHandler) GetHistory ¶ added in v1.0.0
GetHistory returns the message history for a session.
func (*ChatHandler) Process ¶ added in v1.0.0
func (h *ChatHandler) Process(ctx context.Context, req ChatRequest) (*ChatResponse, error)
Process handles a chat request.
type ChatRequest ¶
type ChatRequest struct {
TenantID string `json:"tenant_id"`
UserID string `json:"user_id"`
SessionID string `json:"session_id"`
Message string `json:"message"`
}
ChatRequest is the input for chat endpoint.
type ChatResponse ¶
type ChatResponse struct {
SessionID string `json:"session_id"`
Message string `json:"message"`
SkillUsed string `json:"skill_used,omitempty"`
}
ChatResponse is the output from chat endpoint.
type ExecutionRecord ¶
type ExecutionRecord struct {
ExecutionID string `json:"execution_id"`
SessionID string `json:"session_id"`
SkillID string `json:"skill_id"`
DurationMs int64 `json:"duration_ms"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
}
ExecutionRecord is a single execution entry.
type ExecutionStore ¶
type ExecutionStore interface {
QueryExecutions(ctx context.Context, limit int) ([]ExecutionRecord, error)
}
ExecutionStore provides access to execution history.
type HistoryProvider ¶
type HistoryProvider interface {
// GetSessionHistory retrieves messages for a session.
GetSessionHistory(ctx context.Context, sessionID string) ([]Message, error)
}
HistoryProvider gives access to conversation history.
type HistoryResponse ¶
type HistoryResponse struct {
SessionID string `json:"session_id"`
Messages []Message `json:"messages"`
}
HistoryResponse contains conversation history.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds simple counters for Prometheus-style exposition. This is a lightweight stub — a full implementation would use prometheus/client_golang, but keeping zero external dependencies for the initial stub.
func (*Metrics) Handler ¶
func (m *Metrics) Handler() http.HandlerFunc
Handler returns an http.HandlerFunc that exposes metrics in Prometheus text exposition format.
func (*Metrics) IncRequests ¶
func (m *Metrics) IncRequests()
IncRequests increments the total request counter.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router handles HTTP routing.
The Router is responsible ONLY for:
- HTTP request/response handling
- Request validation
- Session management
- Delegating to Agent
The Router does NOT:
- Select skills (that's the Agent's job)
- Execute skills (that's the Executor's job)
- Make any decisions about which skill to use
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler.
func (*Router) SetAuthMiddleware ¶
SetAuthMiddleware sets an authentication middleware to be used for all /v1/ endpoints. This should be called before requests begin processing.
func (*Router) SetExecutionStore ¶
func (r *Router) SetExecutionStore(es ExecutionStore)
SetExecutionStore sets the execution store for the /v1/executions endpoint.
func (*Router) SetHistoryProvider ¶
func (r *Router) SetHistoryProvider(hp HistoryProvider)
SetHistoryProvider sets the history provider for the /v1/sessions/{id}/history endpoint.
func (*Router) SetSkillProvider ¶
func (r *Router) SetSkillProvider(sp SkillProvider)
SetSkillProvider sets the skill registry for the /v1/skills endpoint.
type SSEHandler ¶
type SSEHandler struct {
// contains filtered or unexported fields
}
SSEHandler writes SSE events to an HTTP response.
func NewSSEHandler ¶
func NewSSEHandler(w http.ResponseWriter) *SSEHandler
NewSSEHandler creates a new SSE handler.
func (*SSEHandler) WriteEvent ¶
func (h *SSEHandler) WriteEvent(event SSEEvent) error
WriteEvent writes a single SSE event.
type SSEStream ¶
type SSEStream struct {
// contains filtered or unexported fields
}
SSEStream buffers events for streaming.
type SkillProvider ¶
SkillProvider provides access to loaded skills for the API.
type SkillResponse ¶
type SkillResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
InputSchema interface{} `json:"input_schema,omitempty"`
OutputSchema interface{} `json:"output_schema,omitempty"`
Version string `json:"version"`
Enabled bool `json:"enabled"`
}
SkillResponse is the JSON representation of a skills.