common

package
v0.260430.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssistantMessage

type AssistantMessage struct {
	Model        string         `json:"model"`
	ID           string         `json:"id"`
	Type         string         `json:"type"`
	Role         string         `json:"role"`
	Content      []ContentBlock `json:"content"`
	StopReason   *string        `json:"stop_reason,omitempty"`
	StopSequence *string        `json:"stop_sequence,omitempty"`
	Usage        *UsageInfo     `json:"usage,omitempty"`
}

AssistantMessage represents the full assistant message structure

type AssistantMessageEvent

type AssistantMessageEvent struct {
	Message AssistantMessage `json:"message"`
}

AssistantMessageEvent represents an assistant message

func (AssistantMessageEvent) EventType

func (AssistantMessageEvent) EventType() string

type ContentBlock

type ContentBlock struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	ID       string `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	Input    string `json:"input,omitempty"`
	Thinking string `json:"thinking,omitempty"`
}

ContentBlock represents a content block in the assistant message

type ErrInvalidPath

type ErrInvalidPath struct {
	Path string
	Err  error
}

ErrInvalidPath is returned when a path cannot be resolved

func (ErrInvalidPath) Error

func (e ErrInvalidPath) Error() string

func (ErrInvalidPath) Unwrap

func (e ErrInvalidPath) Unwrap() error

Unwrap implements the errors.Unwrap interface

type ErrInvalidSessionFormat

type ErrInvalidSessionFormat struct {
	File string
	Err  error
}

ErrInvalidSessionFormat is returned when a session file has invalid format

func (ErrInvalidSessionFormat) Error

func (e ErrInvalidSessionFormat) Error() string

func (ErrInvalidSessionFormat) Unwrap

func (e ErrInvalidSessionFormat) Unwrap() error

Unwrap implements the errors.Unwrap interface

type ErrProjectNotFound

type ErrProjectNotFound struct {
	ProjectPath string
}

ErrProjectNotFound is returned when a project path has no sessions

func (ErrProjectNotFound) Error

func (e ErrProjectNotFound) Error() string

type ErrSessionNotFound

type ErrSessionNotFound struct {
	SessionID string
}

ErrSessionNotFound is returned when a session ID cannot be found

func (ErrSessionNotFound) Error

func (e ErrSessionNotFound) Error() string

type EventData

type EventData interface {
	EventType() string
}

EventData is a union type for different event types Implementations should provide EventType() method for type discrimination

type FileHistorySnapshotEvent

type FileHistorySnapshotEvent struct {
	MessageID string `json:"messageId"`
	Snapshot  struct {
		MessageID          string                 `json:"messageId"`
		TrackedFileBackups map[string]interface{} `json:"trackedFileBackups"`
		Timestamp          string                 `json:"timestamp"`
	} `json:"snapshot"`
	IsSnapshotUpdate bool `json:"isSnapshotUpdate"`
}

FileHistorySnapshotEvent represents file history snapshot

func (FileHistorySnapshotEvent) EventType

func (FileHistorySnapshotEvent) EventType() string

type ResultEvent

type ResultEvent struct {
	Subtype       string    `json:"subtype"`
	Result        string    `json:"result"`
	TotalCostUSD  float64   `json:"total_cost_usd"`
	DurationMS    int       `json:"duration_ms"`
	DurationAPIMS int       `json:"duration_api_ms,omitempty"`
	NumTurns      int       `json:"num_turns"`
	Usage         UsageInfo `json:"usage"`
	Error         string    `json:"error,omitempty"`
}

ResultEvent represents the final result event

func (ResultEvent) EventType

func (ResultEvent) EventType() string

type SessionEvent

type SessionEvent struct {
	Type      string    `json:"type"`
	Subtype   string    `json:"subtype,omitempty"`
	Timestamp time.Time `json:"timestamp"`
	Data      EventData `json:"data"`
}

SessionEvent represents a single event in the session

type SessionMetadata

type SessionMetadata struct {
	SessionID   string        `json:"session_id"`
	ProjectPath string        `json:"project_path"`
	Status      SessionStatus `json:"status"`

	// Time information
	StartTime  time.Time `json:"start_time"`
	EndTime    time.Time `json:"end_time,omitempty"`
	DurationMS int64     `json:"duration_ms,omitempty"`

	// Session summary
	FirstMessage         string `json:"first_message,omitempty"`          // User's first prompt
	LastUserMessage      string `json:"last_user_message,omitempty"`      // Last user message (for context)
	LastAssistantMessage string `json:"last_assistant_message,omitempty"` // Last assistant response
	LastResult           string `json:"last_result,omitempty"`            // Final result/error message
	NumTurns             int    `json:"num_turns,omitempty"`              // Number of exchanges

	// Usage metrics
	InputTokens     int     `json:"input_tokens,omitempty"`
	OutputTokens    int     `json:"output_tokens,omitempty"`
	CacheReadTokens int     `json:"cache_read_tokens,omitempty"`
	TotalCostUSD    float64 `json:"total_cost_usd,omitempty"`

	// Error (if failed)
	Error string `json:"error,omitempty"`
}

SessionMetadata holds parsed session information

type SessionStatus

type SessionStatus string

SessionStatus represents session state

const (
	SessionStatusActive   SessionStatus = "active"
	SessionStatusComplete SessionStatus = "complete"
	SessionStatusError    SessionStatus = "error"
)

type SessionStore

type SessionStore interface {
	// ListSessions returns all sessions for a project, ordered by start time (newest first)
	ListSessions(ctx context.Context, projectPath string) ([]SessionMetadata, error)

	// GetSession retrieves a specific session's metadata
	GetSession(ctx context.Context, sessionID string) (*SessionMetadata, error)

	// GetRecentSessions returns the N most recent sessions
	GetRecentSessions(ctx context.Context, projectPath string, limit int) ([]SessionMetadata, error)

	// GetSessionEvents retrieves events from a session
	// offset: number of events to skip
	// limit: maximum number of events to return (0 = all)
	GetSessionEvents(ctx context.Context, sessionID string, offset, limit int) ([]SessionEvent, error)

	// GetSessionSummary returns a summary (first N and last M events)
	GetSessionSummary(ctx context.Context, sessionID string, firstN, lastM int) (*SessionSummary, error)
}

SessionStore defines the session storage interface

type SessionSummary

type SessionSummary struct {
	Metadata SessionMetadata `json:"metadata"`
	Head     []SessionEvent  `json:"head"` // First N events
	Tail     []SessionEvent  `json:"tail"` // Last M events
}

SessionSummary contains head and tail events

type SystemEvent

type SystemEvent struct {
	Subtype    string `json:"subtype"`
	DurationMS int    `json:"durationMs,omitempty"`
	UUID       string `json:"uuid,omitempty"`
	IsMeta     bool   `json:"isMeta,omitempty"`
}

SystemEvent represents generic system events (duration, etc.)

func (SystemEvent) EventType

func (SystemEvent) EventType() string

type SystemInitEvent

type SystemInitEvent struct {
	SessionID string `json:"session_id"`
	Timestamp string `json:"timestamp"`
}

SystemInitEvent represents session initialization

func (SystemInitEvent) EventType

func (SystemInitEvent) EventType() string

type ToolResultEvent

type ToolResultEvent struct {
	ToolUseID string `json:"tool_use_id"`
	Content   string `json:"content,omitempty"`
	IsError   bool   `json:"is_error,omitempty"`
	Output    string `json:"output,omitempty"`
}

ToolResultEvent represents a tool result event

func (ToolResultEvent) EventType

func (ToolResultEvent) EventType() string

type ToolUseEvent

type ToolUseEvent struct {
	Name      string `json:"name"`
	Input     string `json:"input"`
	ToolUseID string `json:"tool_use_id"`
}

ToolUseEvent represents a tool use event

func (ToolUseEvent) EventType

func (ToolUseEvent) EventType() string

type UsageInfo

type UsageInfo struct {
	InputTokens              int `json:"input_tokens"`
	OutputTokens             int `json:"output_tokens"`
	CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"`
	CacheReadInputTokens     int `json:"cache_read_input_tokens,omitempty"`
}

UsageInfo represents token usage information

type UserMessageEvent

type UserMessageEvent struct {
	ParentUUID  *string `json:"parentUuid"`
	IsSidechain bool    `json:"isSidechain"`
	UserType    string  `json:"userType"`
	CWD         string  `json:"cwd"`
	SessionID   string  `json:"sessionId"`
	Version     string  `json:"version"`
	GitBranch   string  `json:"gitBranch"`
	Type        string  `json:"type"`
	Message     struct {
		Role    string `json:"role"`
		Content string `json:"content"`
	} `json:"message"`
	UUID      string `json:"uuid"`
	Timestamp string `json:"timestamp"`
}

UserMessageEvent represents a user message

func (UserMessageEvent) EventType

func (UserMessageEvent) EventType() string

Jump to

Keyboard shortcuts

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