thread

package
v0.0.0-...-7ad5d0e Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageResourceType = "thread-message"
)
View Source
const ResourceType = "thread"

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	threadv1alpha1connect.UnimplementedThreadServiceHandler
	// contains filtered or unexported fields
}

Service implements the ThreadService

func New

func New(log *logger.Logger, db *database.Pool, jobQueue *job_queue.Client, nc *nats.Conn, m *metrics.Metrics, analyticsClient *analytics.Client) (*Service, error)

New creates a new thread service

func (*Service) CreateThread

CreateThread creates a new thread

func (*Service) ForkThread

ForkThread creates a new thread from an existing thread

func (*Service) GetLlmMessage

GetLlmMessage retrieves an LLM message of a thread

func (*Service) GetStreamManager

func (s *Service) GetStreamManager() *StreamManager

GetStreamManager returns the stream manager for external registration

func (*Service) GetThread

GetThread retrieves a thread by ID

func (*Service) GetThreadEventListener

func (s *Service) GetThreadEventListener() *natslistener.ThreadEventListener

GetThreadEventListener returns the thread event listener for external handler registration

func (*Service) HandleThreadEvent

func (s *Service) HandleThreadEvent(nc *nats.Conn, pool *pgxpool.Pool) func(ctx context.Context, envelope events.ThreadEventEnvelope)

HandleThreadEvent processes unified thread event notifications and broadcasts to streams

func (*Service) ListLlmMessages

ListLlmMessages lists all messages of a thread

func (*Service) ListThreads

ListThreads lists threads for a user

func (*Service) NewServiceHandler

func (s *Service) NewServiceHandler(opts ...connect.HandlerOption) (string, http.Handler)

NewServiceHandler returns a connect service path and handler

func (*Service) Shutdown

func (s *Service) Shutdown() error

Shutdown gracefully stops the thread service

func (*Service) StreamThreadEvents

StreamThreadEvents streams thread events (content, tool calls, state changes) for a thread

func (*Service) SubmitUserMessage

SubmitUserMessage submits a new user message to a thread

func (*Service) UpdateThread

UpdateThread updates an existing thread

type StreamManager

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

func NewStreamManager

func NewStreamManager(m *metrics.Metrics, log *logger.Logger) *StreamManager

func (*StreamManager) BroadcastContentDelta

func (sm *StreamManager) BroadcastContentDelta(threadUID uuid.UUID, event *threadv1.ContentDeltaEvent)

BroadcastContentDelta sends a content delta event to all streams subscribed to a thread.

func (*StreamManager) BroadcastContentStart

func (sm *StreamManager) BroadcastContentStart(threadUID uuid.UUID, event *threadv1.ContentStartEvent)

BroadcastContentStart sends a content start event to all streams subscribed to a thread. If a stream fails to send, it is automatically unsubscribed.

func (*StreamManager) BroadcastContentStop

func (sm *StreamManager) BroadcastContentStop(threadUID uuid.UUID, event *threadv1.ContentStopEvent)

BroadcastContentStop sends a content stop event to all streams subscribed to a thread.

func (*StreamManager) BroadcastStreamError

func (sm *StreamManager) BroadcastStreamError(threadUID uuid.UUID, event *threadv1.StreamErrorEvent)

BroadcastStreamError sends a stream error event to all streams subscribed to a thread.

func (*StreamManager) BroadcastThreadStateChange

func (sm *StreamManager) BroadcastThreadStateChange(threadUID uuid.UUID, event *threadv1.ThreadStateChangeEvent)

BroadcastThreadStateChange sends a thread state change event to all streams subscribed to a thread.

func (*StreamManager) BroadcastToolCall

func (sm *StreamManager) BroadcastToolCall(threadUID uuid.UUID, toolCall *toolv1.ToolCall)

BroadcastToolCall sends a tool call to all streams subscribed to a thread.

func (*StreamManager) Subscribe

func (sm *StreamManager) Subscribe(ctx context.Context, threadUID uuid.UUID, stream StreamSender) func()

Subscribe registers a stream to receive updates for a specific thread. Returns an unsubscribe function that should be called when the stream closes.

func (*StreamManager) Unsubscribe

func (sm *StreamManager) Unsubscribe(threadUID uuid.UUID, sub *streamSubscription)

Unsubscribe removes a stream subscription.

type StreamSender

StreamSender is an alias for the generic streaming.Sender interface specialized for thread events.

Jump to

Keyboard shortcuts

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