chatstore

package
v0.20260527.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTurnUsageDisplayToLastAssistant added in v0.20260525.0

func ApplyTurnUsageDisplayToLastAssistant(s *Session, ctxTok, usrTok int64, ctxEst bool, reasonTok, respTok, totalTok int64, outputTPS, ttftSecs, promptTPS, turnWallSecs float64)

func AssistantDisplayParts

func AssistantDisplayParts(m Message) (reasoning string, visibleContent string)

func BackfillAssistantUsageFromTextIfEmpty

func BackfillAssistantUsageFromTextIfEmpty(m *Message, prior []Message)

func BackfillSessionAssistantUsage added in v0.20260525.0

func BackfillSessionAssistantUsage(msgs []Message)

func ChatIDHex

func ChatIDHex(title string, ts time.Time) string

func ChatsDir

func ChatsDir(projectHex string) (string, error)

func FinishSessionLoad

func FinishSessionLoad(s *Session)

func IsPlaceholderChatID

func IsPlaceholderChatID(id string) bool

func MessageCheckpointTagVisible

func MessageCheckpointTagVisible(m Message) bool

func MigrateImagePathsAfterChatRename

func MigrateImagePathsAfterChatRename(projectHex string, s *Session, oldChatID, newChatID string) error

func MigrateLegacyCheckpointsToBase0

func MigrateLegacyCheckpointsToBase0(s *Session)

func NewPlaceholderChatID

func NewPlaceholderChatID(t time.Time) string

func PlansDir

func PlansDir(projectHex string) (string, error)

func ProjectWelcomeStats

func ProjectWelcomeStats(projectHex string) (chatCount int, userSum, reasonSum, respSum int64, err error)

func PruneUnreferencedSessionImages

func PruneUnreferencedSessionImages(s *Session)

func RebuildProjectStats added in v0.20260526.3

func RebuildProjectStats(projectHex string) error

func ReconcileCheckpointLast

func ReconcileCheckpointLast(s *Session)

func RemoveBrokenSessionImageFiles

func RemoveBrokenSessionImageFiles(s *Session) int

func RemoveSessionPath

func RemoveSessionPath(projectHex, chatID string) error

func RenameSessionFile

func RenameSessionFile(projectHex, oldID, newID string) (err error)

func RepairSessionMalformedImages

func RepairSessionMalformedImages(s *Session) (brokenDropped int, userMsgsAdjusted int, emptyRewrites int)

func RewriteEmptyUserMsgsAfterImageRepair

func RewriteEmptyUserMsgsAfterImageRepair(s *Session) int

func SessionPath

func SessionPath(projectHex, chatIDHex string) (string, error)

func StoredUsageLineForTurnRange added in v0.20260525.0

func StoredUsageLineForTurnRange(msgs []Message, start, end int) (contextTok, lastUserTok, reasoningTok, responseTok, totalTok int64, outputTPS, ttftSecs, promptTPS, turnWallSecs float64, contextEstimated bool, ok bool)

StoredUsageLineForTurnRange returns the usage line fields shown live at end of a user turn.

func StripAllImgPlaceholders

func StripAllImgPlaceholders(content string) string

func StripImgPlaceholderTags

func StripImgPlaceholderTags(content string) string

func StripStaleUserImgPlaceholdersFromSession

func StripStaleUserImgPlaceholdersFromSession(s *Session) int

func StripUnresolvedImgPlaceholders

func StripUnresolvedImgPlaceholders(content string, imageFiles map[int]string) string

func SubchatPath

func SubchatPath(projectHex, idHex string) (string, error)

func SubchatsDir

func SubchatsDir(projectHex string) (string, error)

func TempDir added in v0.20260522.0

func TempDir(projectHex string) (string, error)

func TouchProjectStatsAfterRemove added in v0.20260526.3

func TouchProjectStatsAfterRemove(projectHex, chatID string) error

func TouchProjectStatsAfterRename added in v0.20260526.3

func TouchProjectStatsAfterRename(projectHex, oldID, newID string) error

func WriteSession

func WriteSession(projectHex string, s *Session) (err error)

Types

type MainOrphanSegment

type MainOrphanSegment struct {
	ForkAtInclusive int       `json:"fork_at"`
	Messages        []Message `json:"messages"`
}

type Message

type Message struct {
	Role          string     `json:"role"`
	Content       string     `json:"content"`
	APIContent    string     `json:"api_content,omitempty"`
	ToolCallID    string     `json:"tool_call_id,omitempty"`
	ToolCalls     []ToolCall `json:"tool_calls,omitempty"`
	ReasoningText string     `json:"reasoning_text,omitempty"`

	CheckpointSeq       int    `json:"cp_seq,omitempty"`
	CpSeqSet            bool   `json:"cp_set,omitempty"`
	CheckpointBranchKey string `json:"cp_branch,omitempty"`
	CommitOID           string `json:"commit_oid,omitempty"`

	UserPromptTokens   int64   `json:"user_prompt_tokens"`
	ReasoningTokens    int64   `json:"reasoning_tokens"`
	ResponseTokens     int64   `json:"response_tokens"`
	TurnTotalTokens    int64   `json:"turn_total_tokens"`
	PromptTokens       int64   `json:"prompt_tokens,omitempty"`
	CachedPromptTokens int64   `json:"cached_prompt_tokens,omitempty"`
	OutputTPS          float64 `json:"output_tps,omitempty"`
	TTFTSecs           float64 `json:"ttft_secs,omitempty"`
	PromptTPS          float64 `json:"prompt_tps,omitempty"`
	TurnWallSecs       float64 `json:"turn_wall_secs,omitempty"`

	TurnDisplaySaved  bool    `json:"turn_display_saved,omitempty"`
	TurnContextTokens int64   `json:"turn_context_tokens,omitempty"`
	TurnContextEst    bool    `json:"turn_context_est,omitempty"`
	TurnUserTokens    int64   `json:"turn_user_tokens,omitempty"`
	TurnReasonTokens  int64   `json:"turn_reason_tokens,omitempty"`
	TurnRespTokens    int64   `json:"turn_resp_tokens,omitempty"`
	TurnTotalDisplay  int64   `json:"turn_total_display,omitempty"`
	TurnOutputTPS     float64 `json:"turn_output_tps,omitempty"`
	TurnTTFTSecs      float64 `json:"turn_ttft_secs,omitempty"`
	TurnPromptTPS     float64 `json:"turn_prompt_tps,omitempty"`
	TurnWallDisplay   float64 `json:"turn_wall_display_secs,omitempty"`
}

type Session

type Session struct {
	ID                string    `json:"id"`
	Title             string    `json:"title"`
	CreatedAt         time.Time `json:"created_at"`
	LastMessageAt     time.Time `json:"last_message_at"`
	LastUserMessageAt time.Time `json:"last_user_message_at,omitempty"`
	Messages          []Message `json:"messages"`

	CheckpointLast           int                 `json:"checkpoint_last"`
	CheckpointCP0            bool                `json:"cp0,omitempty"`
	CheckpointBranchSuffix   string              `json:"cp_branch_suffix,omitempty"`
	ForkChildCount           map[int]int         `json:"fork_child_count,omitempty"`
	MainOrphans              []MainOrphanSegment `json:"main_orphans,omitempty"`
	LastCommitOID            string              `json:"last_commit_oid,omitempty"`
	ImageSeq                 int                 `json:"image_seq,omitempty"`
	ImageFiles               map[int]string      `json:"image_files,omitempty"`
	ActivatedInstructionDirs []string            `json:"activated_instruction_dirs,omitempty"`
}

func FindByTitle

func FindByTitle(projectHex, title string) (*Session, error)

func ListRecent

func ListRecent(projectHex string, n int) ([]*Session, error)

func ReadSession

func ReadSession(projectHex, chatIDHex string) (sess *Session, err error)

func SessionWithLatestUserMessage

func SessionWithLatestUserMessage(projectHex string) (*Session, error)

type ToolCall

type ToolCall struct {
	ID        string `json:"id,omitempty"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`

	CheckpointSeq       int    `json:"cp_seq,omitempty"`
	CpSeqSet            bool   `json:"cp_set,omitempty"`
	CheckpointBranchKey string `json:"cp_branch,omitempty"`
}

Jump to

Keyboard shortcuts

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