Documentation
¶
Index ¶
- Variables
- func DatabasePath() string
- func DefaultProviders() map[string]SessionProvider
- func ListAllSessions() (map[string][]SessionSummary, error)
- func Register(agentType string, provider SessionProvider)
- type Message
- type MessageRole
- type MessageType
- type Session
- type SessionProvider
- type SessionSummary
- type TokenUsage
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProviderNotFound is returned when a provider for an agent type is not found. ErrProviderNotFound = errors.New("session provider not found for agent type") // ErrSessionNotFound is returned when a session cannot be found. ErrSessionNotFound = errors.New("session not found") // ErrProjectNotFound is returned when a project has no sessions. ErrProjectNotFound = errors.New("project not found") )
Functions ¶
func DatabasePath ¶
func DatabasePath() string
DatabasePath returns the path to the OpenCode SQLite database if it exists. Returns empty string if the database is not found.
func DefaultProviders ¶
func DefaultProviders() map[string]SessionProvider
DefaultProviders returns all registered providers.
func ListAllSessions ¶
func ListAllSessions() (map[string][]SessionSummary, error)
ListAllSessions returns all sessions across all providers and projects.
func Register ¶
func Register(agentType string, provider SessionProvider)
Register registers a session provider for the given agent type.
Types ¶
type Message ¶
type Message struct {
ID string `json:"id"`
ParentID string `json:"parent_id,omitempty"`
SessionID string `json:"session_id"`
Role MessageRole `json:"role"`
Type MessageType `json:"type"`
Content string `json:"content"`
Model string `json:"model,omitempty"`
Timestamp time.Time `json:"timestamp"`
Usage *TokenUsage `json:"usage,omitempty"`
RawJSON json.RawMessage `json:"raw_json,omitempty"`
}
Message represents a single message in a session.
type MessageRole ¶
type MessageRole string
MessageRole represents the role of a message sender.
const ( RoleUser MessageRole = "user" RoleAssistant MessageRole = "assistant" RoleSystem MessageRole = "system" RoleTool MessageRole = "tool" )
type MessageType ¶
type MessageType string
MessageType represents the type of message.
const ( TypeChat MessageType = "chat" TypeToolUse MessageType = "tool-use" TypeToolResult MessageType = "tool-result" TypeProgress MessageType = "progress" TypeSnapshot MessageType = "snapshot" )
type Session ¶
type Session struct {
SessionSummary
Messages []Message `json:"messages"`
Version string `json:"version,omitempty"`
}
Session represents a complete conversation session.
type SessionProvider ¶
type SessionProvider interface {
// AgentType returns the agent type this provider handles.
AgentType() string
// ListProjects returns a list of project paths that have sessions for this agent.
ListProjects() ([]string, error)
// ListSessions returns session metadata for a given project path.
ListSessions(projectPath string) ([]SessionSummary, error)
// ReadSession returns a complete session with all messages.
ReadSession(sessionID string) (*Session, error)
// ScanMessages iterates through messages in a session, calling fn for each.
// Useful for streaming large sessions without loading all into memory.
ScanMessages(sessionID string, fn func(*Message) error) error
}
SessionProvider is the interface that must be implemented by session data providers.
func ProviderFor ¶
func ProviderFor(agentType string) (SessionProvider, error)
ProviderFor returns the session provider for the given agent type.
type SessionSummary ¶
type SessionSummary struct {
ID string `json:"id"`
AgentType string `json:"agent_type"`
ProjectPath string `json:"project_path"`
GitBranch string `json:"git_branch,omitempty"`
FirstPrompt string `json:"first_prompt,omitempty"`
Summary string `json:"summary,omitempty"`
MessageCount int `json:"message_count"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
}
SessionSummary contains metadata about a session.