Documentation
¶
Index ¶
- type Manager
- func (m *Manager) AddMessage(msg fantasy.Message) error
- func (m *Manager) AddMessages(msgs []fantasy.Message) error
- func (m *Manager) GetFilePath() string
- func (m *Manager) GetMessages() []fantasy.Message
- func (m *Manager) GetSession() *Session
- func (m *Manager) MessageCount() int
- func (m *Manager) ReplaceAllMessages(msgs []fantasy.Message) error
- func (m *Manager) Save() error
- func (m *Manager) SetMetadata(metadata Metadata) error
- type Message
- type Metadata
- type Session
- type ToolCall
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 ¶
NewManager creates a new session manager with a fresh session.
func NewManagerWithSession ¶
NewManagerWithSession creates a new session manager with an existing session.
func (*Manager) AddMessage ¶
AddMessage adds a fantasy message to the session and auto-saves.
func (*Manager) AddMessages ¶
AddMessages adds multiple fantasy messages to the session and auto-saves.
func (*Manager) GetFilePath ¶
GetFilePath returns the file path for this session.
func (*Manager) GetMessages ¶
GetMessages returns all messages as fantasy.Message slice.
func (*Manager) GetSession ¶
GetSession returns a copy of the current session.
func (*Manager) MessageCount ¶
MessageCount returns the number of messages in the session.
func (*Manager) ReplaceAllMessages ¶
ReplaceAllMessages replaces all messages in the session with the provided messages.
func (*Manager) SetMetadata ¶
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
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
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 ¶
LoadFromFile loads a session from a JSON file.
func (*Session) AddMessage ¶
AddMessage adds a message to the session.
func (*Session) SaveToFile ¶
SaveToFile saves the session to a JSON file.
func (*Session) SetMetadata ¶
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.