conversations

package
v0.8.4-beta Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package conversations defines types and interfaces for conversation data structures, query options, and conversation records used throughout kodelet's conversation management system.

Index

Constants

View Source
const (
	// ParentConversationIDMetadataKey stores the explicit hierarchy parent, independently of fork provenance.
	ParentConversationIDMetadataKey = "parent_conversation_id"
	// ConversationForkMetadataKey stores durable conversation fork lineage.
	ConversationForkMetadataKey = "conversation_fork"
	// ConversationForkMetadataVersion is the current fork metadata schema version.
	ConversationForkMetadataVersion = 1
	// RunnerIDMetadataKey identifies a conversation whose environment belongs to a remote runner.
	RunnerIDMetadataKey = "runner_id"
	// RunnerEnvironmentProfileMetadataKey stores the runner-local profile independently from model policy.
	RunnerEnvironmentProfileMetadataKey = "environment_profile"
	// CodexResponsesWindowGenerationMetadataKey stores the logical Codex Responses
	// context-window generation. Forks intentionally start a new generation lineage.
	CodexResponsesWindowGenerationMetadataKey = "codex_responses_window_generation"
)
View Source
const (
	SearchEntryKindTitle      = "title"
	SearchEntryKindText       = "text"
	SearchEntryKindToolUse    = "tool-use"
	SearchEntryKindCompaction = "compaction"
)
View Source
const MaxSearchMatches = 10

Variables

View Source
var ErrConversationNotFound = errors.New("conversation not found")

ErrConversationNotFound identifies a missing durable conversation record.

Functions

func ContextWithConversationForkAsChild

func ContextWithConversationForkAsChild(ctx context.Context, asChild bool) context.Context

ContextWithConversationForkAsChild declares whether a fork also establishes hierarchy.

func ContextWithConversationForkInitiator

func ContextWithConversationForkInitiator(ctx context.Context, initiator ConversationForkInitiator) context.Context

ContextWithConversationForkInitiator attaches the operation requesting a live fork.

func ContextWithTurnAdmission

func ContextWithTurnAdmission(ctx context.Context, admission TurnAdmission) context.Context

ContextWithTurnAdmission asks the store to atomically save history and affinity.

func ConversationForkAsChildFromContext

func ConversationForkAsChildFromContext(ctx context.Context) bool

ConversationForkAsChildFromContext reports whether the requested fork is a child.

func GenerateID

func GenerateID() string

GenerateID creates a unique identifier for a conversation

func GetDefaultBasePath

func GetDefaultBasePath() (string, error)

GetDefaultBasePath returns the default path for storing conversations

func ParentConversationIDFromMetadata

func ParentConversationIDFromMetadata(metadata map[string]any) string

ParentConversationIDFromMetadata returns the explicitly declared parent, never a fork source.

Types

type CompactedSegment

type CompactedSegment struct {
	RawMessages json.RawMessage           `json:"rawMessages"`
	Marker      llmtypes.CompactionMarker `json:"marker"`
}

CompactedSegment contains only the visible tail preceding its completed marker.

type CompactionHistory

type CompactionHistory struct {
	Segments           []CompactedSegment `json:"segments"`
	ActiveDisplayStart int                `json:"activeDisplayStart"`
}

CompactionHistory preserves display history independently of active model input.

func (*CompactionHistory) Append

func (h *CompactionHistory) Append(raw json.RawMessage, replacementCount int, marker llmtypes.CompactionMarker) (*CompactionHistory, error)

Append returns a new archive; the receiver remains unchanged on success or failure.

func (*CompactionHistory) Clone

Clone returns an isolated archive, including the underlying JSON bytes.

func (*CompactionHistory) Validate

func (h *CompactionHistory) Validate(raw json.RawMessage) error

Validate checks the persisted-item boundary without changing inference input.

func (*CompactionHistory) VisibleMessages

func (h *CompactionHistory) VisibleMessages(raw json.RawMessage) (json.RawMessage, error)

VisibleMessages excludes replacement/bootstrap items before provider normalization.

type ConversationForkInitiator

type ConversationForkInitiator struct {
	Type        string `json:"type"`
	ExtensionID string `json:"extension_id,omitempty"`
	ToolName    string `json:"tool_name,omitempty"`
}

ConversationForkInitiator identifies the host operation that requested a fork.

func ConversationForkInitiatorFromContext

func ConversationForkInitiatorFromContext(ctx context.Context) (ConversationForkInitiator, bool)

ConversationForkInitiatorFromContext returns the operation requesting a live fork.

func ConversationForkInitiatorFromMetadata

func ConversationForkInitiatorFromMetadata(metadata map[string]any) (ConversationForkInitiator, bool)

ConversationForkInitiatorFromMetadata returns the operation that created a persisted fork.

type ConversationForkMetadata

type ConversationForkMetadata struct {
	Version              int                        `json:"version"`
	SourceConversationID string                     `json:"source_conversation_id"`
	RootConversationID   string                     `json:"root_conversation_id"`
	Depth                int                        `json:"depth"`
	Mode                 ConversationForkMode       `json:"mode"`
	Initiator            *ConversationForkInitiator `json:"initiator,omitempty"`
}

ConversationForkMetadata describes the durable lineage of a forked conversation.

type ConversationForkMode

type ConversationForkMode string

ConversationForkMode identifies how the source state was obtained.

const (
	// ConversationForkModeLiveSnapshot captures the active in-memory thread state.
	ConversationForkModeLiveSnapshot ConversationForkMode = "live_snapshot"
	// ConversationForkModeStoredCopy duplicates an already persisted conversation record.
	ConversationForkModeStoredCopy ConversationForkMode = "stored_copy"
	// ConversationForkInitiatorTypeExtensionTool identifies an extension tool request.
	ConversationForkInitiatorTypeExtensionTool = "extension_tool"
)

type ConversationForkOptions

type ConversationForkOptions struct {
	Mode      ConversationForkMode
	Initiator *ConversationForkInitiator
	AsChild   bool
}

ConversationForkOptions configures metadata attached to a forked conversation.

type ConversationRecord

type ConversationRecord struct {
	ID                string                                `json:"id"`
	CWD               string                                `json:"cwd,omitempty"`
	RawMessages       json.RawMessage                       `json:"rawMessages"` // Raw LLM provider messages
	CompactionHistory *CompactionHistory                    `json:"compactionHistory,omitempty"`
	Provider          string                                `json:"provider"` // e.g., "anthropic"
	Usage             llmtypes.Usage                        `json:"usage"`
	Summary           string                                `json:"summary,omitempty"`
	CreatedAt         time.Time                             `json:"createdAt"`
	UpdatedAt         time.Time                             `json:"updatedAt"`
	Metadata          map[string]any                        `json:"metadata,omitempty"`
	ToolResults       map[string]tools.StructuredToolResult `json:"toolResults,omitempty"` // Maps tool_call_id to structured result
}

ConversationRecord represents a persisted conversation with its messages and metadata

func ForkConversationRecord

func ForkConversationRecord(source ConversationRecord) ConversationRecord

ForkConversationRecord creates an isolated copy of a conversation while resetting cumulative usage and preserving context-window accounting.

func ForkConversationRecordWithOptions

func ForkConversationRecordWithOptions(source ConversationRecord, options ConversationForkOptions) ConversationRecord

ForkConversationRecordWithOptions creates an isolated conversation copy and records its durable lineage.

func NewConversationRecord

func NewConversationRecord(id string) ConversationRecord

NewConversationRecord creates a new conversation record with a unique ID

func (*ConversationRecord) ToSummary

func (cr *ConversationRecord) ToSummary() ConversationSummary

ToSummary converts a ConversationRecord to a ConversationSummary

type ConversationSearchResult

type ConversationSearchResult struct {
	MatchCount int           `json:"matchCount"`
	Matches    []SearchMatch `json:"matches,omitempty"`
}

type ConversationSummary

type ConversationSummary struct {
	ID                   string                    `json:"id"`
	ParentConversationID string                    `json:"parentConversationId,omitempty"`
	CWD                  string                    `json:"cwd,omitempty"`
	MessageCount         int                       `json:"messageCount"`
	FirstMessage         string                    `json:"firstMessage"`
	Summary              string                    `json:"summary,omitempty"`
	Provider             string                    `json:"provider"`
	Metadata             map[string]any            `json:"metadata,omitempty"`
	Usage                llmtypes.Usage            `json:"usage"`
	CreatedAt            time.Time                 `json:"createdAt"`
	UpdatedAt            time.Time                 `json:"updatedAt"`
	IsRunning            bool                      `json:"isRunning,omitempty"`
	Search               *ConversationSearchResult `json:"search,omitempty"`
}

ConversationSummary provides a brief overview of a conversation

func (ConversationSummary) GetCreatedAt

func (cs ConversationSummary) GetCreatedAt() time.Time

GetCreatedAt returns the creation timestamp of the conversation

func (ConversationSummary) GetID

func (cs ConversationSummary) GetID() string

GetID returns the conversation ID for usage.ConversationSummary compatibility

func (ConversationSummary) GetMessageCount

func (cs ConversationSummary) GetMessageCount() int

GetMessageCount returns the number of messages in the conversation

func (ConversationSummary) GetProvider

func (cs ConversationSummary) GetProvider() string

GetProvider returns the LLM provider name used for the conversation

func (ConversationSummary) GetUpdatedAt

func (cs ConversationSummary) GetUpdatedAt() time.Time

GetUpdatedAt returns the last update timestamp of the conversation

func (ConversationSummary) GetUsage

func (cs ConversationSummary) GetUsage() llmtypes.Usage

GetUsage returns the LLM usage statistics for the conversation

type QueryOptions

type QueryOptions struct {
	StartDate *time.Time
	EndDate   *time.Time
	// SearchTerm covers titles, IDs, CWDs, messages, tool inputs, and compaction
	// summaries. Bare words match prefixes; quoted text is exact. All terms
	// must match one entry.
	SearchTerm    string
	SearchMatches int // Highlighted matches to return per conversation when searching
	Provider      string
	CWD           string // Filter by canonical working directory
	RunnerID      string // Filter by durable runner affinity
	Limit         int
	Offset        int
	SortBy        string // Field to sort by; "relevance" requires a search term
	SortOrder     string // "asc" or "desc"
}

QueryOptions provides filtering and sorting options for conversation queries

type QueryResult

type QueryResult struct {
	ConversationSummaries []ConversationSummary `json:"conversationSummaries"`
	Total                 int                   `json:"total"`          // Represents the total number of the entries that match the query without pagination
	CWDs                  []string              `json:"cwds,omitempty"` // All distinct persisted working directories, independent of pagination
	QueryOptions
}

QueryResult represents the result of a query operation

type SearchDocument

type SearchDocument struct {
	ConversationID string
	// SourceUpdatedAt is the conversation's updated_at value the entries were extracted from.
	SourceUpdatedAt time.Time
	// Version identifies the extraction rules; a different version forces a rebuild.
	Version     int
	ContentHash string
	Entries     []SearchEntry
}

SearchDocument replaces every search entry of one conversation.

type SearchEntry

type SearchEntry struct {
	// EntryIndex is the entry's position in the full display transcript; the title uses -1.
	EntryIndex int
	Role       string
	Kind       string
	Payload    string
}

type SearchIndexCandidate

type SearchIndexCandidate struct {
	ID        string    `db:"id"`
	UpdatedAt time.Time `db:"updated_at"`
}

SearchIndexCandidate identifies a conversation whose search entries are missing or stale.

type SearchMatch

type SearchMatch struct {
	EntryIndex int    `json:"entryIndex"`
	Role       string `json:"role,omitempty"`
	Kind       string `json:"kind"`
	Snippet    string `json:"snippet"`
}

SearchMatch snippets wrap matched terms in "**".

type TurnAdmission

type TurnAdmission struct {
	ConversationID     string
	RunID              string
	RunnerID           string
	EnvironmentProfile string
}

TurnAdmission fences an ordinary conversation checkpoint to a durable running receipt and its exact reserved runner run. Only central orchestration sets it.

func TurnAdmissionFromContext

func TurnAdmissionFromContext(ctx context.Context) (TurnAdmission, bool)

TurnAdmissionFromContext returns the checkpoint's exact admission fence.

Jump to

Keyboard shortcuts

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