usecase

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPairingNotFound  = errors.New("pairing request not found")
	ErrPairingExpired   = errors.New("pairing request expired")
	ErrNonceMismatch    = errors.New("nonce mismatch")
	ErrSenderFailed     = errors.New("sending magic-link failed")
	ErrAlreadyConfirmed = errors.New("pairing request already confirmed")
	ErrCSRFMismatch     = errors.New("csrf token mismatch")
)

Sentinel errors for the pairing flow.

View Source
var (
	ErrAliasInvalid           = errors.New("alias format is invalid")
	ErrAliasTaken             = errors.New("alias already used by another project")
	ErrAliasConflictsWithName = errors.New("alias conflicts with existing project name or slug")
	ErrAliasLimitReached      = errors.New("alias limit reached for project")
	ErrAliasNotFound          = errors.New("alias not found for project")
	ErrAliasForbiddenForInbox = errors.New("aliases are not allowed for the Inbox project")
	ErrProjectNotFound        = errors.New("project not found")
)
View Source
var ErrTaskNotFound = errors.New("task not found")

ErrTaskNotFound — sentinel для случаев, когда задача отсутствует. Оборачивается через fmt.Errorf("...: %w", ErrTaskNotFound), чтобы isNotFoundErr (api/projects.go) распознавал not-found и возвращал HTTP 404 вместо 500.

Functions

func NewChatService

func NewChatService(deps ChatServiceDeps) model.ChatService

NewChatService creates a ChatService that delegates processing to the agent. It also accumulates touched task/project IDs via context: TaskService and ProjectService inside agent tools find the touched sets in ctx and append IDs of affected entities. After the agent replies, ChatService returns the collected IDs in ChatReply and publishes a chat_reply event via EventStore/Broker.

Per-client history isolation is achieved via msg.Source.AccountID: the /v1/chat HTTP handler sets Source{AccountID: "client:<device_id>"} and a HistoryFn that reads the same source group. ChatService passes msg to the agent unmodified — the agent and its tools already operate on msg.Source.

func NewClientVoiceConsumer added in v0.7.0

func NewClientVoiceConsumer(deps ClientVoiceConsumerDeps) model.VoiceConsumer

NewClientVoiceConsumer creates a model.VoiceConsumer for HTTP API client voice jobs. DB, History, Events, Broker, and Chat are required; Tasks may be nil.

func NewPairingService

func NewPairingService(deps PairingDeps) model.PairingService

NewPairingService creates an implementation of model.PairingService.

func NewProjectService

func NewProjectService(deps ProjectServiceDeps) model.ProjectService

NewProjectService creates a ProjectService that wraps write operations in a transaction and publishes events via EventStore/Broker/PushQueue.

func NewTaskService

func NewTaskService(deps TaskServiceDeps) model.TaskService

NewTaskService creates a TaskService that wraps write operations in a transaction and publishes events via EventStore/Broker/PushQueue.

func Slugify

func Slugify(name string) string

Types

type Agent

type Agent interface {
	Handle(ctx context.Context, msg model.Message) (string, error)
}

Agent is the interface for processing messages via a tool-calling loop.

type ChatServiceDeps

type ChatServiceDeps struct {
	// Agent is the message handler (tool-calling loop).
	Agent Agent
	// DB is the database used to open a transaction for publishing chat_reply.
	// If nil, no event is published (ChatService acts as a thin wrapper).
	DB *sql.DB
	// Events is the domain event store; if nil, chat_reply is not published.
	Events model.EventStore
	// Broker is the in-memory SSE broker; Notify is called after commit (nil allowed).
	Broker model.Broker
}

ChatServiceDeps collects the dependencies for ChatService.

type ClientVoiceConsumerDeps added in v0.7.0

type ClientVoiceConsumerDeps struct {
	DB      *sql.DB
	History model.History
	Events  model.EventStore
	Broker  model.Broker
	Chat    model.ChatService
	// Tasks is used to resolve the optional project hint from job.ProjectID.
	// May be nil; hint resolution is skipped when nil.
	Tasks  model.TaskStore
	Logger *slog.Logger
}

ClientVoiceConsumerDeps collects the dependencies for clientVoiceConsumer.

type PairingBroadcaster

type PairingBroadcaster interface {
	Subscribe(pairID string) (<-chan model.PairingResult, func())
	Notify(pairID string, result model.PairingResult)
}

PairingBroadcaster delivers the pairing confirmation result to long-poll subscribers.

type PairingDeps

type PairingDeps struct {
	DB              *sql.DB
	PairingStore    model.PairingStore
	DeviceStore     model.DeviceStore
	Sender          PairingNotifier
	Broadcaster     PairingBroadcaster
	OwnerChatID     int64
	LinkTTL         time.Duration
	LongPoll        time.Duration
	ExternalBaseURL string
	Now             func() time.Time
	// Rand is used for generating bearer tokens.
	// Defaults to crypto/rand.Reader when nil.
	Rand   io.Reader
	Logger *slog.Logger
	// Relay is the push relay client. Defaults to NilRelayClient (push disabled) when nil.
	Relay push.RelayClient
}

PairingDeps collects the dependencies for PairingService.

type PairingNotifier

type PairingNotifier interface {
	SendMagicLink(ctx context.Context, chatID int64, deviceName, magicURL string) error
}

PairingNotifier sends a magic-link DM to the instance owner.

type ProjectServiceDeps

type ProjectServiceDeps struct {
	// DB is the database used to open write transactions.
	DB *sql.DB
	// Tasks is the task and project store (write methods are tx-aware).
	Tasks model.TaskStore
	// Meta is the channel metadata store (write methods are tx-aware).
	Meta model.MetaStore
	// Events is the domain event store; shares the same transaction.
	Events model.EventStore
	// Devices is the client device store (source of active device IDs).
	Devices model.DeviceStore
	// Queue is the push job queue (enqueued within the tx).
	Queue model.PushQueue
	// Broker is the in-memory SSE broker; Notify is called after commit.
	Broker model.Broker
}

ProjectServiceDeps collects the dependencies for ProjectService.

type TaskServiceDeps

type TaskServiceDeps struct {
	// DB is the database used to open write transactions.
	DB *sql.DB
	// Tasks is the task and project store (write methods are tx-aware).
	Tasks model.TaskStore
	// Events is the domain event store; shares the same transaction.
	Events model.EventStore
	// Devices is the client device store (source of active device IDs).
	Devices model.DeviceStore
	// Queue is the push job queue (enqueued within the tx).
	Queue model.PushQueue
	// Broker is the in-memory SSE broker; Notify is called after commit.
	Broker model.Broker
}

TaskServiceDeps collects the dependencies for TaskService.

Jump to

Keyboard shortcuts

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