session

package
v0.1.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteModelPreference

func DeleteModelPreference(database *db.DB, id string) error

DeleteModelPreference removes a model preference from the database.

func Now

func Now() int64

func SetModelPreference

func SetModelPreference(database *db.DB, p *ModelPreference) error

SetModelPreference upserts a model preference into the database.

Types

type MessageID

type MessageID = id.MessageID

func NewMessageID

func NewMessageID() MessageID

type MessageInfo

type MessageInfo struct {
	ID        MessageID    `json:"id"`
	SessionID SessionID    `json:"sessionId"`
	Role      MessageRole  `json:"role"`
	Agent     string       `json:"agent,omitempty"`
	ParentID  *MessageID   `json:"parentId,omitempty"`
	Finish    *string      `json:"finish,omitempty"`
	Cost      float64      `json:"cost,omitempty"`
	Tokens    *TokenCounts `json:"tokens,omitempty"`
	Error     *string      `json:"error,omitempty"`
	CreatedAt int64        `json:"createdAt"`
}

type MessageRole

type MessageRole string
const (
	RoleUser      MessageRole = "user"
	RoleAssistant MessageRole = "assistant"
)

type MessageWithParts

type MessageWithParts struct {
	Info  MessageInfo `json:"info"`
	Parts []Part      `json:"parts"`
}

type ModelPreference

type ModelPreference struct {
	ID          string `json:"id"`
	Enabled     bool   `json:"enabled"`
	ProviderID  string `json:"providerId"`
	DisplayName string `json:"displayName"`
	IsCustom    bool   `json:"isCustom"`
	CreatedAt   int64  `json:"createdAt"`
	UpdatedAt   int64  `json:"updatedAt"`
}

func GetModelPreferences

func GetModelPreferences(database *db.DB) ([]*ModelPreference, error)

GetModelPreferences returns all model preference overrides from the database.

type ModelPreferenceStore

type ModelPreferenceStore struct{}

type Part

type Part struct {
	ID        PartID          `json:"id"`
	MessageID MessageID       `json:"messageId"`
	SessionID SessionID       `json:"sessionId"`
	Type      PartType        `json:"type"`
	Data      json.RawMessage `json:"data"`
	CreatedAt int64           `json:"createdAt"`
	UpdatedAt int64           `json:"updatedAt"`
}

type PartID

type PartID = id.PartID

func NewPartID

func NewPartID() PartID

type PartType

type PartType string
const (
	PartText      PartType = "text"
	PartTool      PartType = "tool"
	PartReasoning PartType = "reasoning"
	PartFile      PartType = "file"
)

type PermissionID

type PermissionID = id.PermissionID

func NewPermissionID

func NewPermissionID() PermissionID

type ReasoningPartData

type ReasoningPartData struct {
	Text string `json:"text"`
}

type Session

type Session struct {
	ID                SessionID `json:"id"`
	ProjectID         string    `json:"projectId"`
	Directory         string    `json:"directory"`
	Title             string    `json:"title"`
	Model             string    `json:"model,omitempty"`
	SessionType       string    `json:"sessionType,omitempty"`
	Permission        string    `json:"permission,omitempty"`
	CompactionSummary string    `json:"compactionSummary,omitempty"`
	CreatedAt         int64     `json:"createdAt"`
	UpdatedAt         int64     `json:"updatedAt"`
}

type SessionID

type SessionID = id.SessionID

func NewSessionID

func NewSessionID() SessionID

type Store

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

func NewStore

func NewStore(database *db.DB) *Store

func (*Store) Create

func (s *Store) Create(session *Session) error

func (*Store) CreateMessage

func (s *Store) CreateMessage(msg *MessageInfo) error

func (*Store) CreatePart

func (s *Store) CreatePart(part *Part) error

func (*Store) Delete

func (s *Store) Delete(id SessionID) error

func (*Store) Get

func (s *Store) Get(id SessionID) (*Session, error)

func (*Store) GetMessage

func (s *Store) GetMessage(messageID MessageID) (*MessageWithParts, error)

func (*Store) GetMessages

func (s *Store) GetMessages(sessionID SessionID, before MessageID, limit int) ([]*MessageWithParts, error)

func (*Store) GetPart

func (s *Store) GetPart(partID PartID) (*Part, error)

func (*Store) GetParts

func (s *Store) GetParts(messageID MessageID) ([]Part, error)

func (*Store) List

func (s *Store) List(directory string) ([]*Session, error)

func (*Store) Update

func (s *Store) Update(session *Session) error

func (*Store) UpdateCompactionSummary

func (s *Store) UpdateCompactionSummary(id SessionID, summary string) error

UpdateCompactionSummary updates only the compaction_summary column for a session, avoiding the race condition of overwriting other fields (e.g., title, model) that may have changed concurrently.

func (*Store) UpdateMessage

func (s *Store) UpdateMessage(msg *MessageInfo) error

func (*Store) UpdatePart

func (s *Store) UpdatePart(part *Part) error

type TextPartData

type TextPartData struct {
	Text string `json:"text"`
}

type TokenCounts

type TokenCounts struct {
	Total      int `json:"total,omitempty"`
	Input      int `json:"input,omitempty"`
	Output     int `json:"output,omitempty"`
	Reasoning  int `json:"reasoning,omitempty"`
	CacheRead  int `json:"cacheRead,omitempty"`
	CacheWrite int `json:"cacheWrite,omitempty"`
}

type ToolPartData

type ToolPartData struct {
	Tool   string    `json:"tool"`
	CallID string    `json:"callId"`
	State  ToolState `json:"state"`
}

type ToolState

type ToolState struct {
	Status   ToolStatus      `json:"status"`
	Input    json.RawMessage `json:"input"`
	Output   *string         `json:"output,omitempty"`
	Error    *string         `json:"error,omitempty"`
	Title    *string         `json:"title,omitempty"`
	Metadata json.RawMessage `json:"metadata,omitempty"`
	Time     ToolTime        `json:"time"`
}

type ToolStatus

type ToolStatus string
const (
	ToolPending   ToolStatus = "pending"
	ToolRunning   ToolStatus = "running"
	ToolCompleted ToolStatus = "completed"
	ToolError     ToolStatus = "error"
)

type ToolTime

type ToolTime struct {
	Start int64 `json:"start,omitempty"`
	End   int64 `json:"end,omitempty"`
}

Jump to

Keyboard shortcuts

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