seahorse

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OrdinalStep is the gap between ordinals in context_items.
	// Insert at midpoint; resequence only when precision exhausted.
	OrdinalStep = 100

	// ContextThreshold is the compaction trigger for the context window.
	ContextThreshold float64 = 0.75 // Compact at 75% of context window
	FreshTailCount   int     = 32   // Recent messages protected from compaction

	// LeafMinFanout is the fanout parameter.
	LeafMinFanout          int = 8 // Min messages per leaf summary
	CondensedMinFanout     int = 4 // Min summaries per condensed
	CondensedMinFanoutHard int = 2 // Min for forced compaction

	// LeafChunkTokens is the token target.
	LeafChunkTokens       int = 20000 // Max tokens per leaf chunk
	LeafTargetTokens      int = 1200  // Target tokens for leaf summaries
	CondensedTargetTokens int = 2000  // Target tokens for condensed summaries
	MaxExpandTokens       int = 4000  // Token cap for expansion queries

	// MaxCompactIterations caps CompactUntilUnder to prevent infinite loops.
	// Each iteration reduces ~4x tokens via leaf (8:1) or condensed (4:1) compaction.
	// With a 200k token context window and 75% threshold, ~20 iterations is enough
	// for any realistic scenario. If exceeded, the issue is logged as a warning.
	MaxCompactIterations int = 20
)

Variables

This section is empty.

Functions

func EstimateMessageTokens

func EstimateMessageTokens(msg Message) int

EstimateMessageTokens estimates token count for a full message using the shared tokenizer package for consistency with agent.context_budget.

func FormatSummaryXML

func FormatSummaryXML(s *Summary, parentIDs []string) string

FormatSummaryXML formats a summary as XML for LLM context. This is exported so context managers can format summaries consistently.

func ParseLastDuration

func ParseLastDuration(s string) (time.Duration, error)

ParseLastDuration parses a "last" duration string like "6h", "7d", "2w", "1m". Returns the duration and nil error, or zero and error if invalid.

func SanitizeFTS5Query

func SanitizeFTS5Query(raw string) string

SanitizeFTS5Query escapes user input for safe use in an FTS5 MATCH expression.

FTS5 treats certain characters as operators:

  • `-` (NOT), `+` (required), `*` (prefix), `^` (initial token)
  • `OR`, `AND`, `NOT`, `NEAR` (boolean/proximity operators)
  • `:` (column filter — e.g. `agent:foo` means "search column agent")
  • `"` (phrase query), `(` `)` (grouping)

Strategy: wrap each whitespace-delimited token in double quotes so FTS5 treats it as a literal phrase token. User-quoted phrases ("...") are preserved as-is. Internal double quotes are stripped. Empty tokens are dropped. Tokens are joined with spaces (implicit AND).

Returns empty string for blank input so callers can skip the MATCH query.

Examples:

"sub-agent restrict"  →  `"sub-agent" "restrict"`
"lcm_expand OR crash" →  `"lcm_expand" "OR" "crash"`
`hello "world"`       →  `"hello" "world"`

Types

type AssembleInput

type AssembleInput struct {
	Budget int    `json:"budget"`
	Query  string `json:"query,omitempty"`
}

AssembleInput controls context assembly.

type AssembleResult

type AssembleResult struct {
	Messages []Message `json:"messages"`
	Summary  string    `json:"summary"` // formatted XML summaries + system prompt addition
}

AssembleResult contains assembled context.

type Assembler

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

Assembler handles budget-aware context assembly (defined in short_assembler.go).

func (*Assembler) Assemble

func (a *Assembler) Assemble(ctx context.Context, convID int64, input AssembleInput) (*AssembleResult, error)

Assemble builds budget-constrained context from summaries + messages.

Algorithm:

  1. Fetch context_items, resolve to full content
  2. Split into evictable prefix + protected fresh tail
  3. If evictable fits in remaining budget → include all
  4. Else walk evictable from newest to oldest, keep while fits

type CompactInput

type CompactInput struct {
	Budget *int // Token budget override
	Force  bool // Force compaction even if below threshold
}

CompactInput controls compaction behavior.

type CompactResult

type CompactResult struct {
	SummariesCreated   []string `json:"summariesCreated"`
	TokensSaved        int      `json:"tokensSaved"`
	LeafSummaries      int      `json:"leafSummaries"`
	CondensedSummaries int      `json:"condensedSummaries"`
}

CompactResult describes what was compacted.

type CompactionEngine

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

CompactionEngine handles LLM-based summarization (defined in short_compaction.go).

func (*CompactionEngine) Close

func (e *CompactionEngine) Close()

Close cancels the shutdown context, stopping async goroutines.

func (*CompactionEngine) Compact

func (e *CompactionEngine) Compact(ctx context.Context, convID int64, input CompactInput) (*CompactResult, error)

Compact runs leaf compaction (sync) and optionally condensed compaction.

func (*CompactionEngine) CompactUntilUnder

func (e *CompactionEngine) CompactUntilUnder(ctx context.Context, convID int64, budget int) (*CompactResult, error)

CompactUntilUnder aggressively compacts until context is under budget.

func (*CompactionEngine) NeedsCompaction

func (e *CompactionEngine) NeedsCompaction(ctx context.Context, convID int64, contextWindow int) (bool, error)

NeedsCompaction returns true if context tokens >= ContextThreshold × contextWindow.

type CompleteFn

type CompleteFn func(ctx context.Context, prompt string, opts CompleteOptions) (string, error)

CompleteFn is the LLM completion function type.

type CompleteOptions

type CompleteOptions struct {
	Model       string
	MaxTokens   int
	Temperature float64
}

CompleteOptions holds LLM completion parameters.

type Config

type Config struct {
	DBPath                   string   `json:"dbPath"`
	IgnoreSessionPatterns    []string `json:"ignoreSessionPatterns,omitempty"`
	StatelessSessionPatterns []string `json:"statelessSessionPatterns,omitempty"`
}

Config holds engine configuration.

type ContextItem

type ContextItem struct {
	ConversationID int64     `json:"conversationId"`
	Ordinal        int       `json:"ordinal"`
	ItemType       string    `json:"itemType"` // "summary" or "message"
	SummaryID      string    `json:"summaryId,omitempty"`
	MessageID      int64     `json:"messageId,omitempty"`
	TokenCount     int       `json:"tokenCount"`
	CreatedAt      time.Time `json:"createdAt"`
}

ContextItem represents one item in the assembled context window.

type Conversation

type Conversation struct {
	ConversationID int64     `json:"conversationId"`
	SessionKey     string    `json:"sessionKey"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
}

Conversation represents a session's conversation with metadata.

type CreateSummaryInput

type CreateSummaryInput struct {
	ConversationID       int64
	Kind                 SummaryKind
	Depth                int
	Content              string
	TokenCount           int
	EarliestAt           *time.Time
	LatestAt             *time.Time
	DescendantCount      int
	DescendantTokenCount int
	SourceMessageTokens  int
	Model                string
	ParentIDs            []string // For condensed: child summary IDs being condensed
}

CreateSummaryInput holds parameters for creating a summary.

type Engine

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

Engine is the main short-term memory engine.

func NewEngine

func NewEngine(config Config, completeFn CompleteFn) (*Engine, error)

NewEngine creates a new short-term memory engine.

func (*Engine) Assemble

func (e *Engine) Assemble(ctx context.Context, sessionKey string, input AssembleInput) (*AssembleResult, error)

Assemble builds budget-constrained context for a session.

func (*Engine) Bootstrap

func (e *Engine) Bootstrap(ctx context.Context, sessionKey string, messages []Message) error

Bootstrap reconciles a session's messages with the database. Called once at startup for each known session. Bootstrap reconciles JSONL history with SQLite by ingesting only the delta. Simple approach: find longest matching prefix and append delta. If any mismatch is detected, clear and rebuild.

func (*Engine) ClearSession

func (e *Engine) ClearSession(ctx context.Context, sessionKey string) error

ClearSession removes all stored data for a session (messages, summaries, context). If the session has no prior seahorse record, it is a no-op.

func (*Engine) Close

func (e *Engine) Close() error

Close releases resources.

func (*Engine) Compact

func (e *Engine) Compact(ctx context.Context, sessionKey string, input CompactInput) (*CompactResult, error)

Compact compresses conversation history for a session.

func (*Engine) CompactUntilUnder

func (e *Engine) CompactUntilUnder(ctx context.Context, sessionKey string, budget int) (*CompactResult, error)

CompactUntilUnder aggressively compacts until context is under budget. Used for emergency compaction after LLM overflow (retry reason).

func (*Engine) GetRetrieval

func (e *Engine) GetRetrieval() *RetrievalEngine

GetRetrieval returns the retrieval engine for tool implementations.

func (*Engine) Ingest

func (e *Engine) Ingest(ctx context.Context, sessionKey string, messages []Message) (*IngestResult, error)

Ingest adds messages to a conversation identified by sessionKey.

type ExpandMessagesResult

type ExpandMessagesResult struct {
	Messages   []Message `json:"messages"`
	TokenCount int       `json:"tokenCount"`
}

ExpandMessagesResult contains expanded messages.

type ExpandTool

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

ExpandTool recovers full message content by ID.

func NewExpandTool

func NewExpandTool(engine *RetrievalEngine) *ExpandTool

func (*ExpandTool) Description

func (t *ExpandTool) Description() string

func (*ExpandTool) Execute

func (t *ExpandTool) Execute(ctx context.Context, args map[string]any) *tools.ToolResult

func (*ExpandTool) Name

func (t *ExpandTool) Name() string

func (*ExpandTool) Parameters

func (t *ExpandTool) Parameters() map[string]any

type GrepInput

type GrepInput struct {
	Pattern          string     `json:"pattern"`
	Scope            string     `json:"scope,omitempty"` // "both" (default), "summary", or "message"
	Role             string     `json:"role,omitempty"`  // "user", "assistant", or "" (all)
	AllConversations bool       `json:"allConversations,omitempty"`
	Since            *time.Time `json:"since,omitempty"`
	Before           *time.Time `json:"before,omitempty"`
	Last             string     `json:"last,omitempty"` // shortcut: "6h", "7d", "2w", "1m"
	Limit            int        `json:"limit,omitempty"`
}

GrepInput controls search across summaries and messages.

type GrepMessageResult

type GrepMessageResult struct {
	ID             int64   `json:"id,string"`
	Snippet        string  `json:"snippet"`
	Role           string  `json:"role"`
	ConversationID int64   `json:"conversationId"`
	Rank           float64 `json:"rank,omitempty"` // Relevance score (more negative = better match)
}

GrepMessageResult is a message match from grep.

type GrepResult

type GrepResult struct {
	Success        bool                `json:"success"`
	Summaries      []GrepSummaryResult `json:"summaries"`
	Messages       []GrepMessageResult `json:"messages"`
	TotalSummaries int                 `json:"totalSummaries"`
	TotalMessages  int                 `json:"totalMessages"`
	Hint           string              `json:"hint,omitempty"`
}

GrepResult contains search results.

type GrepSummaryResult

type GrepSummaryResult struct {
	ID             string      `json:"id"`
	Content        string      `json:"content"`
	Depth          int         `json:"depth"`
	Kind           SummaryKind `json:"kind"`
	ConversationID int64       `json:"conversationId"`
	// Rank is the bm25 relevance score (negative value, lower = better match).
	// Examples: -5.0 = excellent match, -2.0 = good match, -0.5 = partial match.
	Rank float64 `json:"rank,omitempty"`
}

GrepSummaryResult is a summary match from grep.

type GrepTool

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

GrepTool searches summaries and messages for matching content.

func NewGrepTool

func NewGrepTool(engine *RetrievalEngine) *GrepTool

func (*GrepTool) Description

func (t *GrepTool) Description() string

func (*GrepTool) Execute

func (t *GrepTool) Execute(ctx context.Context, args map[string]any) *tools.ToolResult

func (*GrepTool) Name

func (t *GrepTool) Name() string

func (*GrepTool) Parameters

func (t *GrepTool) Parameters() map[string]any

type IngestResult

type IngestResult struct {
	MessageCount int `json:"messageCount"`
	TokenCount   int `json:"tokenCount"`
}

IngestResult is the result of message ingestion.

type Message

type Message struct {
	ID               int64         `json:"id"`
	ConversationID   int64         `json:"conversationId"`
	Role             string        `json:"role"`
	Content          string        `json:"content"`
	ModelName        string        `json:"modelName,omitempty"`
	ReasoningContent string        `json:"reasoningContent,omitempty"`
	TokenCount       int           `json:"tokenCount"`
	CreatedAt        time.Time     `json:"createdAt"`
	Parts            []MessagePart `json:"parts,omitempty"`
}

Message represents a single chat message with role and content.

type MessagePart

type MessagePart struct {
	ID         int64  `json:"id"`
	MessageID  int64  `json:"messageId"`
	Type       string `json:"type"` // "text", "tool_use", "tool_result", "media"
	Text       string `json:"text"`
	Name       string `json:"name"`
	Arguments  string `json:"arguments"`
	ToolCallID string `json:"toolCallId"`
	MediaURI   string `json:"mediaUri"`
	MimeType   string `json:"mimeType"`
}

MessagePart holds structured content (tool calls, media, etc.)

type RetrievalEngine

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

RetrievalEngine handles search and expansion (defined in short_retrieval.go).

func (*RetrievalEngine) ExpandMessages

func (r *RetrievalEngine) ExpandMessages(ctx context.Context, messageIDs []int64) (*ExpandMessagesResult, error)

ExpandMessages retrieves full message content by IDs.

func (*RetrievalEngine) Grep

func (r *RetrievalEngine) Grep(ctx context.Context, input GrepInput) (*GrepResult, error)

Grep searches summaries and messages for matching content.

func (*RetrievalEngine) Store

func (r *RetrievalEngine) Store() *Store

Store returns the underlying store for direct access.

type SearchInput

type SearchInput struct {
	Pattern          string     `json:"pattern"`
	Mode             string     `json:"mode"`            // "like" (LIKE search) or "full_text" (FTS5, default)
	Scope            string     `json:"scope,omitempty"` // "messages", "summaries", "both"
	Role             string     `json:"role,omitempty"`  // "user", "assistant", or "" (all)
	Since            *time.Time `json:"since,omitempty"`
	Before           *time.Time `json:"before,omitempty"`
	Limit            int        `json:"limit,omitempty"`
	ConversationID   int64      `json:"conversationId,omitempty"`
	AllConversations bool       `json:"allConversations,omitempty"`
}

SearchInput controls summary search.

type SearchResult

type SearchResult struct {
	SummaryID      string      `json:"summaryId,omitempty"`
	MessageID      int64       `json:"messageId,omitempty"`
	ConversationID int64       `json:"conversationId"`
	Kind           SummaryKind `json:"kind,omitempty"`
	Depth          int         `json:"depth,omitempty"`
	Role           string      `json:"role,omitempty"`
	Content        string      `json:"content,omitempty"` // Full content for summaries
	Snippet        string      `json:"snippet"`
	CreatedAt      time.Time   `json:"createdAt"`
	Rank           float64     `json:"rank,omitempty"`
	TotalCount     int         `json:"totalCount,omitempty"` // Total matching rows (from window function)
}

SearchResult is a search match.

type SessionStatus

type SessionStatus struct {
	SessionKey     string    `json:"sessionKey"`
	ConversationID int64     `json:"conversationId"`
	Messages       int       `json:"messages"`
	TotalTokens    int       `json:"totalTokens"`
	Summaries      int       `json:"summaries"`
	OldestAt       time.Time `json:"oldestAt"`
	NewestAt       time.Time `json:"newestAt"`
}

SessionStatus contains status information for a session.

type Store

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

Store provides SQLite storage for seahorse.

func (*Store) AddMessage

func (s *Store) AddMessage(ctx context.Context, convID int64, role, content string, tokenCount int) (*Message, error)

AddMessage appends a message to a conversation.

func (*Store) AddMessageWithParts

func (s *Store) AddMessageWithParts(
	ctx context.Context,
	convID int64,
	role string,
	parts []MessagePart,
	tokenCount int,
) (*Message, error)

AddMessageWithParts adds a message with structured parts.

func (*Store) AddMessageWithPartsAndReasoning

func (s *Store) AddMessageWithPartsAndReasoning(
	ctx context.Context,
	convID int64,
	role string,
	parts []MessagePart,
	modelName string,
	reasoningContent string,
	tokenCount int,
	createdAt time.Time,
) (*Message, error)

AddMessageWithPartsAndReasoning adds a message with structured parts and reasoning content.

func (*Store) AddMessageWithReasoning

func (s *Store) AddMessageWithReasoning(
	ctx context.Context,
	convID int64,
	role, content, modelName, reasoningContent string,
	tokenCount int,
	createdAt time.Time,
) (*Message, error)

AddMessageWithReasoning appends a message with reasoning content to a conversation.

func (*Store) AppendContextMessage

func (s *Store) AppendContextMessage(ctx context.Context, convID int64, messageID int64) error

AppendContextMessage appends a single message to context_items at next ordinal.

func (*Store) AppendContextMessages

func (s *Store) AppendContextMessages(ctx context.Context, convID int64, messageIDs []int64) error

AppendContextMessages bulk-appends messages to context_items.

func (*Store) AppendContextSummary

func (s *Store) AppendContextSummary(ctx context.Context, convID int64, summaryID string) error

AppendContextSummary appends a summary to context_items at next ordinal.

func (*Store) ClearContextItems

func (s *Store) ClearContextItems(ctx context.Context, convID int64) error

ClearContextItems removes all context items for a conversation.

func (*Store) ClearConversation

func (s *Store) ClearConversation(ctx context.Context, convID int64) error

ClearConversation removes all data for a conversation from all tables. Deletes context_items, summary_messages, summary_parents (via subquery), summaries, message_parts, and messages. FTS entries are handled automatically by triggers. Uses a transaction for atomicity.

func (*Store) CreateSummary

func (s *Store) CreateSummary(ctx context.Context, input CreateSummaryInput) (*Summary, error)

CreateSummary creates a new summary and indexes it in FTS5.

func (*Store) DeleteMessagesAfterID

func (s *Store) DeleteMessagesAfterID(ctx context.Context, convID int64, afterID int64) error

DeleteMessagesAfterID deletes all messages with ID > afterID for a conversation. Also clears related context_items, message_parts, summary_messages, and FTS entries. Uses transaction to ensure atomicity of the delete cascade.

func (*Store) GetAllSessionStatuses

func (s *Store) GetAllSessionStatuses(ctx context.Context) ([]SessionStatus, error)

GetAllSessionStatuses returns status for all sessions.

func (*Store) GetContextItems

func (s *Store) GetContextItems(ctx context.Context, convID int64) ([]ContextItem, error)

GetContextItems retrieves context items for a conversation, ordered by ordinal.

func (*Store) GetContextTokenCount

func (s *Store) GetContextTokenCount(ctx context.Context, convID int64) (int, error)

GetContextTokenCount returns total token count for all items in context.

func (*Store) GetConversationBySessionKey

func (s *Store) GetConversationBySessionKey(ctx context.Context, sessionKey string) (*Conversation, error)

GetConversationBySessionKey retrieves a conversation by session key.

func (*Store) GetDistinctDepthsInContext

func (s *Store) GetDistinctDepthsInContext(ctx context.Context, convID int64, maxOrdinalExclusive int) ([]int, error)

GetDistinctDepthsInContext returns distinct depth levels of summaries currently in context. maxOrdinalExclusive filters out summaries with ordinal >= this value (0 = no filter).

func (*Store) GetMaxOrdinal

func (s *Store) GetMaxOrdinal(ctx context.Context, convID int64) (int, error)

GetMaxOrdinal returns the highest ordinal in context_items for a conversation.

func (*Store) GetMaxOrdinalTx

func (s *Store) GetMaxOrdinalTx(ctx context.Context, tx *sql.Tx, convID int64) (int, error)

GetMaxOrdinalTx returns the highest ordinal within a transaction.

func (*Store) GetMessageByID

func (s *Store) GetMessageByID(ctx context.Context, messageID int64) (*Message, error)

GetMessageByID retrieves a single message by ID.

func (*Store) GetMessageCount

func (s *Store) GetMessageCount(ctx context.Context, convID int64) (int, error)

GetMessageCount returns total message count for a conversation.

func (*Store) GetMessages

func (s *Store) GetMessages(ctx context.Context, convID int64, limit int, beforeID int64) ([]Message, error)

GetMessages retrieves messages for a conversation.

func (*Store) GetOrCreateConversation

func (s *Store) GetOrCreateConversation(ctx context.Context, sessionKey string) (*Conversation, error)

GetOrCreateConversation returns the conversation for a sessionKey, creating if needed.

func (*Store) GetRootSummaries

func (s *Store) GetRootSummaries(ctx context.Context, convID int64) ([]Summary, error)

GetRootSummaries retrieves root summaries (not children of any other summary).

func (*Store) GetSessionStatus

func (s *Store) GetSessionStatus(ctx context.Context, sessionKey string) (*SessionStatus, error)

GetSessionStatus returns status for a specific session.

func (*Store) GetSummariesByConversation

func (s *Store) GetSummariesByConversation(ctx context.Context, convID int64) ([]Summary, error)

GetSummariesByConversation retrieves all summaries for a conversation.

func (*Store) GetSummary

func (s *Store) GetSummary(ctx context.Context, summaryID string) (*Summary, error)

GetSummary retrieves a summary by ID.

func (*Store) GetSummaryChildren

func (s *Store) GetSummaryChildren(ctx context.Context, summaryID string) ([]string, error)

GetSummaryChildren retrieves child summary IDs (summaries that list this summary as parent).

func (*Store) GetSummaryParents

func (s *Store) GetSummaryParents(ctx context.Context, summaryID string) ([]Summary, error)

GetSummaryParents retrieves parent summaries (full objects) for a summary.

func (*Store) GetSummarySourceMessages

func (s *Store) GetSummarySourceMessages(ctx context.Context, summaryID string) ([]Message, error)

GetSummarySourceMessages retrieves source messages for a summary.

func (*Store) GetSummarySubtree

func (s *Store) GetSummarySubtree(ctx context.Context, summaryID string) ([]SummarySubtreeNode, error)

GetSummarySubtree returns all summaries in the subtree rooted at summaryID, including summaryID itself. Uses a recursive CTE to traverse the DAG.

func (*Store) LinkSummaryToMessages

func (s *Store) LinkSummaryToMessages(ctx context.Context, summaryID string, messageIDs []int64) error

LinkSummaryToMessages links a leaf summary to its source messages.

func (*Store) ReplaceContextItemsWithSummary

func (s *Store) ReplaceContextItemsWithSummary(
	ctx context.Context,
	convID int64,
	summaryIDs []string,
	newSummaryID string,
) error

ReplaceContextItemsWithSummary replaces specific context items (by summary_id) with a new summary. Use this when candidates are not contiguous in ordinal space to avoid deleting non-candidate items.

func (*Store) ReplaceContextRangeWithSummary

func (s *Store) ReplaceContextRangeWithSummary(
	ctx context.Context,
	convID int64,
	startOrdinal, endOrdinal int,
	summaryID string,
) error

ReplaceContextRangeWithSummary atomically replaces a range of context items with a summary. If ordinal gap is exhausted, triggers resequencing (spec lines 1204-1209).

func (*Store) SearchMessages

func (s *Store) SearchMessages(ctx context.Context, input SearchInput) ([]SearchResult, error)

SearchMessages performs full-text or regex search on messages.

func (*Store) SearchSummaries

func (s *Store) SearchSummaries(ctx context.Context, input SearchInput) ([]SearchResult, error)

SearchSummaries performs full-text search on summaries.

func (*Store) UpdateMessageCreatedAt

func (s *Store) UpdateMessageCreatedAt(ctx context.Context, messageID int64, createdAt time.Time) error

func (*Store) UpdateMessageModelName

func (s *Store) UpdateMessageModelName(ctx context.Context, messageID int64, modelName string) error

func (*Store) UpdateMessageReasoningContent

func (s *Store) UpdateMessageReasoningContent(ctx context.Context, messageID int64, reasoningContent string) error

UpdateMessageReasoningContent updates reasoning_content for an existing message.

func (*Store) UpsertContextItems

func (s *Store) UpsertContextItems(ctx context.Context, convID int64, items []ContextItem) error

UpsertContextItems replaces all context items for a conversation.

type Summary

type Summary struct {
	SummaryID               string      `json:"summaryId"`
	ConversationID          int64       `json:"conversationId"`
	Kind                    SummaryKind `json:"kind"`
	Depth                   int         `json:"depth"`
	Content                 string      `json:"content"`
	TokenCount              int         `json:"tokenCount"`
	EarliestAt              *time.Time  `json:"earliestAt,omitempty"`
	LatestAt                *time.Time  `json:"latestAt,omitempty"`
	DescendantCount         int         `json:"descendantCount"`
	DescendantTokenCount    int         `json:"descendantTokenCount"`
	SourceMessageTokenCount int         `json:"sourceMessageTokenCount"`
	Model                   string      `json:"model"`
	CreatedAt               time.Time   `json:"createdAt"`
}

Summary represents a compressed representation of messages or other summaries.

type SummaryKind

type SummaryKind string

SummaryKind distinguishes leaf summaries (from raw messages) vs condensed summaries (from other summaries).

const (
	SummaryKindLeaf      SummaryKind = "leaf"
	SummaryKindCondensed SummaryKind = "condensed"
)

type SummaryNode

type SummaryNode struct {
	Summary
	Children []string `json:"children"` // Child summary IDs
	Expanded bool     `json:"expanded"` // UI state for expansion
}

SummaryNode is a Summary with graph relationships for tree traversal.

type SummarySubtreeNode

type SummarySubtreeNode struct {
	SummaryID     string `json:"summaryId"`
	DepthFromRoot int    `json:"depthFromRoot"`
}

SummarySubtreeNode is a node in a summary DAG subtree.

Jump to

Keyboard shortcuts

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