session

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export added in v0.7.3

func Export(record *SessionRecord, options ExportOptions) ([]byte, error)

Export serializes record according to the specified options. Supported formats are FormatMarkdown (default if empty) and FormatJSON.

func ExportJSON added in v0.7.3

func ExportJSON(record *SessionRecord, options ExportOptions) ([]byte, error)

ExportJSON serializes record into pretty-printed, deterministic JSON. System prompts and internal reasoning content are strictly excluded.

func ExportMarkdown added in v0.7.3

func ExportMarkdown(record *SessionRecord, options ExportOptions) (string, error)

ExportMarkdown serializes record into clean, human-readable Markdown. System prompts and internal reasoning content are strictly excluded.

func GenerateID

func GenerateID() string

GenerateID creates a unique session identifier.

Types

type ExportFormat added in v0.7.3

type ExportFormat string

ExportFormat specifies the target serialization format for a session.

const (
	FormatMarkdown ExportFormat = "markdown"
	FormatJSON     ExportFormat = "json"
)

type ExportOptions added in v0.7.3

type ExportOptions struct {
	Format       ExportFormat
	IncludeTools bool
}

ExportOptions controls session serialization.

type JSONExportMessage added in v0.7.3

type JSONExportMessage struct {
	Role       string               `json:"role"`
	Content    string               `json:"content"`
	ToolCalls  []JSONExportToolCall `json:"tool_calls,omitempty"`
	ToolCallID string               `json:"tool_call_id,omitempty"`
	ToolName   string               `json:"tool_name,omitempty"`
}

JSONExportMessage represents a single message in the exported JSON.

type JSONExportToolCall added in v0.7.3

type JSONExportToolCall struct {
	ID   string          `json:"id"`
	Name string          `json:"name"`
	Args json.RawMessage `json:"args,omitempty"`
}

JSONExportToolCall represents a tool invocation in the exported JSON.

type JSONSessionExport added in v0.7.3

type JSONSessionExport struct {
	Version   int                 `json:"version"`
	ID        string              `json:"id"`
	Title     string              `json:"title"`
	Provider  string              `json:"provider"`
	Model     string              `json:"model"`
	CreatedAt time.Time           `json:"created_at"`
	UpdatedAt time.Time           `json:"updated_at"`
	Messages  []JSONExportMessage `json:"messages"`
}

JSONSessionExport represents the versioned, privacy-scrubbed JSON structure.

type SessionRecord

type SessionRecord struct {
	ID        string             `json:"id"`
	Title     string             `json:"title"`
	Provider  string             `json:"provider"`
	Model     string             `json:"model"`
	CreatedAt time.Time          `json:"created_at"`
	UpdatedAt time.Time          `json:"updated_at"`
	Messages  []provider.Message `json:"messages"`
}

SessionRecord holds the full data of a persisted session.

type SessionStore

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

SessionStore handles session persistence using SQLite.

func NewStore

func NewStore(dbPath string) (*SessionStore, error)

NewStore opens or creates a SQLite session database at dbPath.

func (*SessionStore) AppendMessage

func (s *SessionStore) AppendMessage(sessionID string, msg provider.Message) error

AppendMessage persists a single message to the given session and updates timestamps.

func (*SessionStore) Close

func (s *SessionStore) Close() error

Close closes the underlying SQLite database.

func (*SessionStore) CreateSession

func (s *SessionStore) CreateSession(id, title, providerName, model string) (*SessionRecord, error)

CreateSession initializes a new session record in the database.

func (*SessionStore) DeleteSession

func (s *SessionStore) DeleteSession(id string) error

DeleteSession deletes a session and all its messages.

func (*SessionStore) GetLastSession

func (s *SessionStore) GetLastSession() (*SessionRecord, error)

GetLastSession returns the most recently updated session, or nil if no sessions exist.

func (*SessionStore) GetSession

func (s *SessionStore) GetSession(id string) (*SessionRecord, error)

GetSession retrieves a session record and its full message history.

func (*SessionStore) ListSessions

func (s *SessionStore) ListSessions(limit int) ([]SessionSummary, error)

ListSessions returns a summary of recent sessions up to limit.

func (*SessionStore) SaveSession

func (s *SessionStore) SaveSession(rec *SessionRecord) error

SaveSession updates session metadata and overwrites all messages.

func (*SessionStore) UpdateModel

func (s *SessionStore) UpdateModel(id, providerName, model string) error

UpdateModel updates the model and provider of an existing session.

type SessionSummary

type SessionSummary struct {
	ID           string    `json:"id"`
	Title        string    `json:"title"`
	Provider     string    `json:"provider"`
	Model        string    `json:"model"`
	MessageCount int       `json:"message_count"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

SessionSummary holds brief metadata about a session for listing.

Jump to

Keyboard shortcuts

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