Documentation
¶
Overview ¶
Package services defines business logic interfaces and domain models for the application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentResult ¶
AgentResult represents the agent's response
type AgentService ¶
type AgentService interface {
// Run executes a prompt (queues if conversation is busy)
Run(ctx context.Context, call AgentCall) (*AgentResult, error)
// Stream executes a prompt with streaming response
Stream(ctx context.Context, call AgentCall) (<-chan StreamEvent, error)
// IsConversationBusy returns true if conversation has active request
IsConversationBusy(convID string) bool
// QueuedPrompts returns number of queued messages for conversation
QueuedPrompts(convID string) int
// CancelConversation cancels active request and clears queue
CancelConversation(convID string)
}
AgentService coordinates LLM interactions with queuing support
func NewAgentService ¶
func NewAgentService(client LLMClient, convSvc ConversationService, msgSvc MessageService) AgentService
NewAgentService creates a new agent service
type Conversation ¶
type Conversation struct {
ID string
Title string
CreatedAt time.Time
UpdatedAt time.Time
PromptTokens int64
CompletionTokens int64
TotalCost float64
SummaryMessageID *string
IsFavorite bool
}
Conversation represents a chat session
type ConversationService ¶
type ConversationService interface {
pubsub.Subscriber[Conversation]
// Create creates a new conversation
Create(ctx context.Context, title string) (*Conversation, error)
// Get retrieves a conversation by ID
Get(ctx context.Context, id string) (*Conversation, error)
// List returns all conversations ordered by updated_at DESC
List(ctx context.Context) ([]*Conversation, error)
// Update saves conversation changes
Update(ctx context.Context, conv *Conversation) error
// Delete removes a conversation and its messages
Delete(ctx context.Context, id string) error
// UpdateTokenUsage updates token counts and calculates cost
UpdateTokenUsage(ctx context.Context, id string, promptTokens, completionTokens int64) error
}
ConversationService manages conversation lifecycle and state
func NewConversationService ¶
func NewConversationService(db *sql.DB) ConversationService
NewConversationService creates a new conversation service with event publishing
type LLMClient ¶
type LLMClient interface {
CreateMessage(ctx context.Context, req core.MessageRequest) (*core.MessageResponse, error)
CreateMessageStream(ctx context.Context, req core.MessageRequest) (<-chan *core.StreamChunk, error)
}
LLMClient defines the interface for interacting with LLM APIs
type Message ¶
type Message struct {
ID string
ConversationID string
Role string
Content string
Provider string
Model string
IsSummary bool
CreatedAt time.Time
}
Message represents a single message in a conversation
type MessageService ¶
type MessageService interface {
pubsub.Subscriber[Message]
// Add stores a new message
Add(ctx context.Context, msg *Message) error
// GetByConversation returns all messages for a conversation
GetByConversation(ctx context.Context, convID string) ([]*Message, error)
// GetSummaries returns only summary messages for a conversation
GetSummaries(ctx context.Context, convID string) ([]*Message, error)
}
MessageService manages message lifecycle
func NewMessageService ¶
func NewMessageService(db *sql.DB) MessageService
NewMessageService creates a new message service with event publishing