session

package
v0.34.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages session state and auto-saving functionality. It provides thread-safe operations for managing a conversation session, including automatic persistence to disk after each modification.

func NewManager

func NewManager(filePath string) *Manager

NewManager creates a new session manager with a fresh session.

func NewManagerWithSession

func NewManagerWithSession(session *Session, filePath string) *Manager

NewManagerWithSession creates a new session manager with an existing session.

func (*Manager) AddMessage

func (m *Manager) AddMessage(msg fantasy.Message) error

AddMessage adds a fantasy message to the session and auto-saves.

func (*Manager) AddMessages

func (m *Manager) AddMessages(msgs []fantasy.Message) error

AddMessages adds multiple fantasy messages to the session and auto-saves.

func (*Manager) GetFilePath

func (m *Manager) GetFilePath() string

GetFilePath returns the file path for this session.

func (*Manager) GetMessages

func (m *Manager) GetMessages() []fantasy.Message

GetMessages returns all messages as fantasy.Message slice.

func (*Manager) GetSession

func (m *Manager) GetSession() *Session

GetSession returns a copy of the current session.

func (*Manager) MessageCount

func (m *Manager) MessageCount() int

MessageCount returns the number of messages in the session.

func (*Manager) ReplaceAllMessages

func (m *Manager) ReplaceAllMessages(msgs []fantasy.Message) error

ReplaceAllMessages replaces all messages in the session with the provided messages.

func (*Manager) Save

func (m *Manager) Save() error

Save manually saves the session to file.

func (*Manager) SetMetadata

func (m *Manager) SetMetadata(metadata Metadata) error

SetMetadata sets the session metadata.

type Message

type Message struct {
	// ID is a unique identifier for this message, auto-generated if not provided
	ID string `json:"id"`
	// Role indicates who sent the message ("user", "assistant", "tool", or "system")
	Role string `json:"role"`
	// Content is the text content of the message
	Content string `json:"content"`
	// Timestamp is when the message was created
	Timestamp time.Time `json:"timestamp"`
	// ToolCalls contains any tool invocations made by the assistant in this message
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
	// ToolCallID links a tool result message to its corresponding tool call
	ToolCallID string `json:"tool_call_id,omitempty"`
}

Message represents a single message in the conversation session. Messages can be from different roles (user, assistant, tool) and may include tool calls for assistant messages or tool results for tool messages.

func ConvertFromFantasyMessage added in v0.34.0

func ConvertFromFantasyMessage(msg fantasy.Message) Message

ConvertFromFantasyMessage converts a fantasy.Message to a session Message. This function bridges between the fantasy message format and the session's internal message format for JSON persistence.

func (*Message) ConvertToFantasyMessage added in v0.34.0

func (m *Message) ConvertToFantasyMessage() fantasy.Message

ConvertToFantasyMessage converts a session Message to a fantasy.Message. This method bridges between the session's internal message format and the fantasy message format used by the LLM providers.

type Metadata

type Metadata struct {
	// MCPHostVersion is the version of MCPHost used for this session
	MCPHostVersion string `json:"mcphost_version"`
	// Provider is the LLM provider used (e.g., "anthropic", "openai", "gemini")
	Provider string `json:"provider"`
	// Model is the specific model identifier used for the conversation
	Model string `json:"model"`
}

Metadata contains session metadata that provides context about the environment and configuration used during the conversation.

type Session

type Session struct {
	// Version indicates the session format version for compatibility
	Version string `json:"version"`
	// CreatedAt is the timestamp when the session was first created
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the timestamp when the session was last modified
	UpdatedAt time.Time `json:"updated_at"`
	// Metadata contains contextual information about the session
	Metadata Metadata `json:"metadata"`
	// Messages is the ordered list of all messages in this session
	Messages []Message `json:"messages"`
}

Session represents a complete conversation session with metadata. It stores all messages exchanged during a conversation along with contextual information about the session such as the provider, model, and timestamps. Sessions can be saved to and loaded from JSON files for persistence across program runs.

func LoadFromFile

func LoadFromFile(filePath string) (*Session, error)

LoadFromFile loads a session from a JSON file.

func NewSession

func NewSession() *Session

NewSession creates a new session with default values.

func (*Session) AddMessage

func (s *Session) AddMessage(msg Message)

AddMessage adds a message to the session.

func (*Session) SaveToFile

func (s *Session) SaveToFile(filePath string) error

SaveToFile saves the session to a JSON file.

func (*Session) SetMetadata

func (s *Session) SetMetadata(metadata Metadata)

SetMetadata sets the session metadata.

type ToolCall

type ToolCall struct {
	// ID is a unique identifier for this tool call, used to link results
	ID string `json:"id"`
	// Name is the name of the tool being invoked
	Name string `json:"name"`
	// Arguments contains the parameters passed to the tool, typically as JSON
	Arguments any `json:"arguments"`
}

ToolCall represents a tool invocation within an assistant message.

Jump to

Keyboard shortcuts

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