session

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyID  = errors.New("session ID cannot be empty")
	ErrNotFound = errors.New("session not found")
)

Functions

This section is empty.

Types

type Item

type Item struct {
	// Message holds a regular conversation message
	Message *Message `json:"message,omitempty"`

	// SubSession holds a complete sub-session from task transfers
	SubSession *Session `json:"sub_session,omitempty"`

	// Summary is a summary of the session up until this point
	Summary string `json:"summary,omitempty"`
}

Item represents either a message or a sub-session

func NewMessageItem

func NewMessageItem(msg *Message) Item

NewMessageItem creates a SessionItem containing a message

func NewSubSessionItem

func NewSubSessionItem(subSession *Session) Item

NewSubSessionItem creates a SessionItem containing a sub-session

func (*Item) IsMessage

func (si *Item) IsMessage() bool

IsMessage returns true if this item contains a message

func (*Item) IsSubSession

func (si *Item) IsSubSession() bool

IsSubSession returns true if this item contains a sub-session

type Message

type Message struct {
	AgentFilename string       `json:"agentFilename"`
	AgentName     string       `json:"agentName"` // TODO: rename to agent_name
	Message       chat.Message `json:"message"`
}

Message is a message from an agent

func NewAgentMessage

func NewAgentMessage(a *agent.Agent, message *chat.Message) *Message

func SystemMessage

func SystemMessage(content string) *Message

func UserMessage

func UserMessage(agentFilename, content string) *Message

type Migration

type Migration struct {
	ID          int
	Name        string
	Description string
	UpSQL       string
	DownSQL     string
	AppliedAt   time.Time
}

Migration represents a database migration

type MigrationManager

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

MigrationManager handles database migrations

func NewMigrationManager

func NewMigrationManager(db *sql.DB) *MigrationManager

NewMigrationManager creates a new migration manager

func (*MigrationManager) GetAppliedMigrations

func (m *MigrationManager) GetAppliedMigrations(ctx context.Context) ([]Migration, error)

GetAppliedMigrations returns a list of applied migrations

func (*MigrationManager) InitializeMigrations

func (m *MigrationManager) InitializeMigrations(ctx context.Context) error

InitializeMigrations sets up the migrations table and runs pending migrations

func (*MigrationManager) RunPendingMigrations

func (m *MigrationManager) RunPendingMigrations(ctx context.Context) error

RunPendingMigrations executes all migrations that haven't been applied yet

type Opt

type Opt func(s *Session)

func WithSystemMessage

func WithSystemMessage(content string) Opt

func WithUserMessage

func WithUserMessage(agentFilename, content string) Opt

type SQLiteSessionStore

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

SQLiteSessionStore implements Store using SQLite

func (*SQLiteSessionStore) AddSession

func (s *SQLiteSessionStore) AddSession(ctx context.Context, session *Session) error

AddSession adds a new session to the store

func (*SQLiteSessionStore) Close

func (s *SQLiteSessionStore) Close() error

Close closes the database connection

func (*SQLiteSessionStore) DeleteSession

func (s *SQLiteSessionStore) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session by ID

func (*SQLiteSessionStore) GetSession

func (s *SQLiteSessionStore) GetSession(ctx context.Context, id string) (*Session, error)

GetSession retrieves a session by ID

func (*SQLiteSessionStore) GetSessions

func (s *SQLiteSessionStore) GetSessions(ctx context.Context) ([]*Session, error)

GetSessions retrieves all sessions

func (*SQLiteSessionStore) UpdateSession

func (s *SQLiteSessionStore) UpdateSession(ctx context.Context, session *Session) error

UpdateSession updates an existing session

type Session

type Session struct {
	// ID is the unique identifier for the session
	ID string `json:"id"`

	// Title is the title of the session, set by the runtime
	Title string `json:"title"`

	// Messages holds the conversation history (messages and sub-sessions)
	Messages []Item `json:"messages"`

	// CreatedAt is the time the session was created
	CreatedAt time.Time `json:"created_at"`

	// ToolsApproved is a flag to indicate if the tools have been approved
	ToolsApproved bool `json:"tools_approved"`

	// SendUserMessage is a flag to indicate if the user message should be sent
	SendUserMessage bool

	InputTokens  int     `json:"input_tokens"`
	OutputTokens int     `json:"output_tokens"`
	Cost         float64 `json:"cost"`
}

Session represents the agent's state including conversation history and variables

func New

func New(opts ...Opt) *Session

New creates a new agent session

func (*Session) AddMessage

func (s *Session) AddMessage(msg *Message)

AddMessage adds a message to the session

func (*Session) AddSubSession

func (s *Session) AddSubSession(subSession *Session)

AddSubSession adds a sub-session to the session

func (*Session) GetAllMessages

func (s *Session) GetAllMessages() []Message

GetAllMessages extracts all messages from the session, including from sub-sessions

func (*Session) GetLastAssistantMessageContent

func (s *Session) GetLastAssistantMessageContent() string

func (*Session) GetMessages

func (s *Session) GetMessages(a *agent.Agent) []chat.Message

func (*Session) GetMostRecentAgentFilename

func (s *Session) GetMostRecentAgentFilename() string

type Store

type Store interface {
	AddSession(ctx context.Context, session *Session) error
	GetSession(ctx context.Context, id string) (*Session, error)
	GetSessions(ctx context.Context) ([]*Session, error)
	DeleteSession(ctx context.Context, id string) error
	UpdateSession(ctx context.Context, session *Session) error
}

Store defines the interface for session storage

func NewSQLiteSessionStore

func NewSQLiteSessionStore(path string) (Store, error)

NewSQLiteSessionStore creates a new SQLite session store

Jump to

Keyboard shortcuts

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