conversations

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package conversations owns the read/list/delete + topic-subscription lifecycle of web conversation threads. The streaming Prompt and multipart UploadFile endpoints stay HTTP-shaped in the api package (they manage NDJSON streams, conversation locks, and multipart form parsing that don't fit cleanly behind a Go-typed service surface).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Detail

type Detail struct {
	Conversation        dbq.AgentConversation
	Messages            []dbq.AgentMessage
	HasOlderMessages    bool
	InFlightRunID       string
	PendingConfirmation *PendingConfirmation
}

Detail is the GetConversation response payload.

type FeedResult

type FeedResult struct {
	Rows       []dbq.ListConversationFeedRow
	NextCursor string
}

FeedResult is one keyset page of the merged sidebar feed plus the cursor for the next (older) page ("" when the end is reached).

type KeyExtractor

type KeyExtractor func(parts []byte, agentID string) []string

KeyExtractor returns the canonical S3 keys referenced by a message's parts JSON. Injected to avoid importing the api package.

type MessagePage

type MessagePage struct {
	Messages []dbq.AgentMessage
	HasMore  bool
}

MessagePage is the body of ListMessages — a paginated slice + a has-more flag for the chat infinite-scroll.

type PendingConfirmation

type PendingConfirmation struct {
	RunID       string
	ToolCallID  string
	ToolName    string
	Permission  string
	Patterns    []string
	Code        string
	Input       string
	Description string
}

PendingConfirmation describes a suspended run's outstanding tool call awaiting user approval.

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(d *db.DB, s3 *storage.S3Client, logger *zap.Logger, extractKeys KeyExtractor) *Service

New constructs the conversations service. s3 and extractKeys may be nil — they are only consulted by Delete's best-effort attachment cleanup; with either nil, Delete just skips the S3 scheduling step. The Delete row write still happens.

func (*Service) Authorize

func (s *Service) Authorize(ctx context.Context, p authz.Principal, agentID uuid.UUID) error

Authorize requires current conversation access to an agent.

func (*Service) Create

func (s *Service) Create(ctx context.Context, p authz.Principal, agentID uuid.UUID, title string) (dbq.AgentConversation, error)

Create makes a new web conversation thread. Requires membership of the agent (AccessUser).

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, p authz.Principal, convID uuid.UUID) error

Delete removes a conversation and schedules S3 cleanup for any attachment blobs its messages referenced. Owner + surface gated like Get; the S3 cleanup is best-effort.

func (*Service) Get

func (s *Service) Get(ctx context.Context, p authz.Principal, convID uuid.UUID) (Detail, error)

Get returns the conversation + the newest page of messages + any in-flight or suspended-run metadata the chat store needs to adopt. Owner + surface gate: caller must own it; a2a transport rows are invisible from the web. Both fail with ErrNotFound (don't leak which conversations exist on which surface).

func (*Service) ListAll

func (s *Service) ListAll(ctx context.Context, p authz.Principal) ([]dbq.AgentConversation, error)

ListAll returns every web conversation the user owns, across all agents (newest first).

func (*Service) ListByAgent

func (s *Service) ListByAgent(ctx context.Context, p authz.Principal, agentID uuid.UUID) ([]dbq.AgentConversation, error)

ListByAgent returns web conversations owned by the user for the given agent (DM-only — there is at most one). Requires membership of the agent (AccessUser).

func (*Service) ListFeed

func (s *Service) ListFeed(ctx context.Context, p authz.Principal, cursor string, limit int32) (FeedResult, error)

ListFeed returns the merged agent+system web-conversation feed, newest-first, keyset-paginated. An empty cursor starts at the most recent item.

func (*Service) ListMessages

func (s *Service) ListMessages(ctx context.Context, p authz.Principal, convID uuid.UUID, before, after string, limitParam string) (MessagePage, error)

ListMessages returns messages before or after a sequence number for infinite scroll. Exactly one of `before` or `after` must be non-empty; `limit` is clamped to 1..500 with a default of 100. Owner and surface checks happen before any message query.

func (*Service) ListTopics

func (s *Service) ListTopics(ctx context.Context, conv dbq.AgentConversation) ([]Topic, error)

ListTopics returns the agent's topics with this conversation's subscription flag set. Caller must have already passed the OwnedConversation gate.

func (*Service) OwnedConversation

func (s *Service) OwnedConversation(ctx context.Context, p authz.Principal, convID uuid.UUID) (dbq.AgentConversation, error)

OwnedConversation enforces the same owner + surface gate as Get / Delete and returns the conversation row for the caller to use. Centralizes the gate used by the topic endpoints.

func (*Service) SubscribeTopic

func (s *Service) SubscribeTopic(ctx context.Context, conv dbq.AgentConversation, slug string) error

SubscribeTopic attaches the conversation to a topic. ErrNotFound for an unknown slug. Caller has already passed the OwnedConversation gate.

func (*Service) UnsubscribeTopic

func (s *Service) UnsubscribeTopic(ctx context.Context, conv dbq.AgentConversation, slug string) error

UnsubscribeTopic detaches the conversation from a topic.

type Topic

type Topic struct {
	ID          uuid.UUID
	Slug        string
	Description string
	Subscribed  bool
}

Topic carries one topic + this conversation's subscription state.

Jump to

Keyboard shortcuts

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