chat

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventAnchor            = "anchor"
	EventDelta             = "delta"
	EventElicitation       = "elicitation"
	EventElicitationResult = "elicitation_result"
	EventError             = "error"
	EventPlan              = "plan"
	EventResult            = "result"
	EventRunner            = "runner"
	EventThinking          = "thinking"
	EventToolCall          = "tool_call"
	EventToolCallUpdate    = "tool_call_update"
	EventUsage             = "usage"
)
View Source
const (
	AccessFull = "full"
	AccessSafe = "safe"
)
View Source
const (
	PartError    = "error"
	PartPlan     = "plan"
	PartText     = "text"
	PartThinking = "thinking"
	PartTool     = "tool"

	ToolStatusCompleted  = "completed"
	ToolStatusFailed     = "failed"
	ToolStatusInProgress = "in_progress"
)
View Source
const StructuralUpdate int64 = 0

Variables

View Source
var (
	ErrAgentUnknown        = errors.New("agent unknown")
	ErrElicitationNotFound = errors.New("elicitation not found")
	ErrElicitationResolved = errors.New("elicitation already resolved")
	ErrNoResolver          = errors.New("no elicitation resolver configured")
	ErrThreadBusy          = errors.New("thread busy")
	ErrThreadNotBusy       = errors.New("thread not busy")
	ErrThreadStateUnknown  = errors.New("thread state unknown")
	ErrTurnPending         = errors.New("turn pending durable recovery")
)
View Source
var ErrAttachmentTooLarge = errors.New("attachment exceeds 32 MiB")

Functions

func AgentName

func AgentName(a Agent) string

func FriendlyDescription

func FriendlyDescription(prompt string) string

func FriendlyTitle

func FriendlyTitle(prompt string) string

func HasRunner

func HasRunner(meta string) bool

func IsThreadBusy

func IsThreadBusy(err error) bool

func IsThreadNotBusy

func IsThreadNotBusy(err error) bool

func MessageProps

func MessageProps(v ThreadView, m db.Message) ui.ChatMessageProps

func NormalizeModel

func NormalizeModel(agent, model string) string

func ParseProviderModel

func ParseProviderModel(value string) (string, string)

func ProviderModelOptions

func ProviderModelOptions(agents []string) []uikit.SelectOption

Types

type Agent

type Agent interface {
	Author() string
	Run(ctx context.Context, turn Turn, emit func(Event)) (string, error)
}

func AvailableAgents

func AvailableAgents() []Agent

func AvailableAgentsInDir

func AvailableAgentsInDir(dir string) []Agent

func ResolveAgent

func ResolveAgent(name string) (Agent, error)

func ResolveAgentInDir

func ResolveAgentInDir(name, dir string) (Agent, error)

func WithDir

func WithDir(agent Agent, dir string) Agent

type Attachment

type Attachment struct {
	MimeType string
	Path     string
}

type Broker

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

func NewBroker

func NewBroker() *Broker

func (*Broker) Publish

func (b *Broker) Publish(threadID, messageID int64)

func (*Broker) Subscribe

func (b *Broker) Subscribe(threadID int64) (<-chan struct{}, func() []int64, func())

type ClaudeAgent

type ClaudeAgent struct {
	Dir string
}

func (ClaudeAgent) Author

func (ClaudeAgent) Author() string

func (ClaudeAgent) Run

func (a ClaudeAgent) Run(ctx context.Context, turn Turn, emit func(Event)) (string, error)

type CodexAgent

type CodexAgent struct {
	Dir string
}

func (CodexAgent) Author

func (CodexAgent) Author() string

func (CodexAgent) Run

func (a CodexAgent) Run(ctx context.Context, turn Turn, emit func(Event)) (string, error)

type EchoAgent

type EchoAgent struct {
	Delay time.Duration
}

func (EchoAgent) Author

func (EchoAgent) Author() string

func (EchoAgent) Run

func (a EchoAgent) Run(ctx context.Context, turn Turn, emit func(Event)) (string, error)

type Event

type Event struct {
	Data string
	Type string
}

func DeltaEvent

func DeltaEvent(text string) Event

type MessagePart

type MessagePart struct {
	Kind string
	Plan []PlanEntry
	Text string
	Tool *ToolCallView
}

type PlanEntry

type PlanEntry struct {
	Content  string `json:"content"`
	Priority string `json:"priority,omitempty"`
	Status   string `json:"status,omitempty"`
}

type Recoverable

type Recoverable interface {
	Alive(turn Turn) bool
}

type Resolver

type Resolver interface {
	Deliver(workflowID, topic, idempotencyKey string, reply elicit.Reply) error
}

type Server

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

func NewServer

func NewServer(svc *Service, log *slog.Logger) *Server

func (*Server) Handler

func (s *Server) Handler() http.Handler

type Service

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

func NewService

func NewService(store db.ThreadStore, agent Agent, log *slog.Logger) *Service

func (*Service) AddAttachment

func (s *Service) AddAttachment(threadID int64, name, mimeType string, r io.Reader) (db.Attachment, error)

func (*Service) AgentName

func (s *Service) AgentName(thread db.Thread) string

func (*Service) AgentNames

func (s *Service) AgentNames() []string

func (*Service) Attachment

func (s *Service) Attachment(id int64) (db.Attachment, error)

func (*Service) Close

func (s *Service) Close()

func (*Service) CreateThread

func (s *Service) CreateThread(agent, title string) (db.Thread, error)

func (*Service) CreateThreadWithLabel

func (s *Service) CreateThreadWithLabel(agent, model, label, title string) (db.Thread, error)

func (*Service) CreateThreadWithModel

func (s *Service) CreateThreadWithModel(agent, model, title string) (db.Thread, error)

func (*Service) DeleteDraftAttachment

func (s *Service) DeleteDraftAttachment(id int64) error

func (*Service) DeleteThread

func (s *Service) DeleteThread(threadID int64) error

func (*Service) Publish

func (s *Service) Publish(threadID int64)

func (*Service) Recover

func (s *Service) Recover() error

func (*Service) RegisterAgent

func (s *Service) RegisterAgent(name string, agent Agent)

func (*Service) ResolveElicitation

func (s *Service) ResolveElicitation(messageID int64, elicitationID, action string, values map[string]string) error

func (*Service) Send

func (s *Service) Send(threadID int64, prompt string, attachmentIDs ...int64) (db.Message, error)

func (*Service) SetResolver

func (s *Service) SetResolver(r Resolver)

func (*Service) SetThreadStarred

func (s *Service) SetThreadStarred(threadID int64, starred bool) error

func (*Service) SetThreadState

func (s *Service) SetThreadState(threadID int64, state string) error

func (*Service) StopThread

func (s *Service) StopThread(threadID int64) error

func (*Service) Subscribe

func (s *Service) Subscribe(threadID int64) (<-chan struct{}, func() []int64, func())

func (*Service) Thread

func (s *Service) Thread(id int64) (db.Thread, error)

func (*Service) ThreadAccess

func (s *Service) ThreadAccess(thread db.Thread) string

func (*Service) ThreadLabel

func (s *Service) ThreadLabel(thread db.Thread) string

func (*Service) ThreadPrompt

func (s *Service) ThreadPrompt(id int64) (string, error)

func (*Service) Threads

func (s *Service) Threads() ([]db.Thread, error)

func (*Service) ThreadsByLabel

func (s *Service) ThreadsByLabel(label string) ([]db.Thread, error)

func (*Service) ToggleThreadAccess

func (s *Service) ToggleThreadAccess(threadID int64) (string, error)

func (*Service) View

func (s *Service) View(threadID int64) (ThreadView, error)

type ThreadView

type ThreadView struct {
	Attachments map[int64][]db.Attachment
	Forms       map[int64]elicit.Prompt
	Messages    []db.Message
	Parts       map[int64][]MessagePart
	Streaming   bool
	Thread      db.Thread
}

type ToolCallView

type ToolCallView struct {
	Detail string
	ID     string
	Status string
	Title  string
}

type Turn

type Turn struct {
	Anchor      string
	Attachments []Attachment
	MessageID   int64
	Meta        string
	Prompt      string
	ThreadID    int64
}

Jump to

Keyboard shortcuts

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