services

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 9 Imported by: 0

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 AgentCall

type AgentCall struct {
	ConversationID string
	Prompt         string
	Attachments    []string
	MaxTokens      int
}

AgentCall represents a request to the agent

type AgentResult

type AgentResult struct {
	Text         string
	ToolCalls    []ToolCall
	PromptTokens int64
	OutputTokens int64
}

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

type StreamEvent

type StreamEvent struct {
	Type         string // "text", "tool_call", "done", "error"
	Text         string
	ToolCall     *ToolCall
	Error        error
	PromptTokens int64
	OutputTokens int64
}

StreamEvent represents a streaming update from the agent

type ToolCall

type ToolCall struct {
	ID     string
	Name   string
	Input  map[string]interface{}
	Result string
}

ToolCall represents a tool execution request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL