Documentation
¶
Overview ¶
Transcript of one conversation with usage totals and pluggable persistence
Index ¶
- Constants
- Variables
- func InvalidID(id string) error
- func MarshalEntry(e Entry) ([]byte, error)
- func MarshalParts(parts []protocol.Part) ([]byte, error)
- func MarshalRecord(r Record) ([]byte, error)
- func SortInfos(infos []Info)
- func ValidID(id string) bool
- type Entry
- type Header
- type Info
- type MarkdownOptions
- type Record
- type Session
- func (s *Session) AddResponse(agent string, r protocol.Response) Entry
- func (s *Session) AddResults(agent string, results []protocol.ToolResult) Entry
- func (s *Session) Append(m protocol.Message) Entry
- func (s *Session) Compact(summary string, keep int) error
- func (s *Session) Context() int
- func (s *Session) Created() time.Time
- func (s *Session) Empty() bool
- func (s *Session) Entries() []Entry
- func (s *Session) Fork() *Session
- func (s *Session) Head(keep int) []Entry
- func (s *Session) Header() Header
- func (s *Session) ID() string
- func (s *Session) Info() Info
- func (s *Session) Label(key, value string)
- func (s *Session) Labels() map[string]string
- func (s *Session) Last() protocol.Usage
- func (s *Session) Len() int
- func (s *Session) Log(agent, kind string, data any) (Record, error)
- func (s *Session) Markdown() string
- func (s *Session) MarkdownWith(o MarkdownOptions) string
- func (s *Session) Model() string
- func (s *Session) Named() bool
- func (s *Session) Parent() string
- func (s *Session) Project() string
- func (s *Session) Prune(callID, stub string)
- func (s *Session) Pruned(callID string) (string, bool)
- func (s *Session) Records() []Record
- func (s *Session) Rename(title string)
- func (s *Session) SetModel(model string)
- func (s *Session) SetTitle(title string)
- func (s *Session) Snapshot() []protocol.Message
- func (s *Session) Title() string
- func (s *Session) Truncate(n int)
- func (s *Session) Updated() time.Time
- func (s *Session) Usage() protocol.Usage
- type Store
- func (st *Store) Busy(id string) bool
- func (st *Store) Close() error
- func (st *Store) Delete(ctx context.Context, id string) error
- func (st *Store) Exists(ctx context.Context, id string) (bool, error)
- func (st *Store) Lease(id string) error
- func (st *Store) Leased(id string) bool
- func (st *Store) List(ctx context.Context) ([]Info, error)
- func (st *Store) ListProject(ctx context.Context, root string) ([]Info, error)
- func (st *Store) Load(ctx context.Context, id string) (*Session, error)
- func (st *Store) Path(id string) (string, error)
- func (st *Store) Save(ctx context.Context, s *Session) error
- func (st *Store) Unlease(id string) error
Constants ¶
const Ack = "Understood. I have the summary of the earlier conversation and will continue from here."
Assistant turn written after a summary so the kept tail still follows an assistant message
const MaxHeaders = 32
Header lines appended between rewrites before the log is compacted into a fresh file
const ProjectLabel = "project"
Label naming the project root a session was started under, by which stores list the sessions of a project
Variables ¶
var ErrBusy = errors.New("session: open in another icebath")
Error of Lease when another process has the session open
var ErrNotFound = errors.New("session: not found")
Error for a session a store does not hold
Functions ¶
func MarshalParts ¶
Serializes parts as the tagged JSON array a stored message carries
Types ¶
type Entry ¶
type Entry struct {
// Position on the shared timeline of entries and records
Seq int
Time time.Time
Agent string
Model string
Usage protocol.Usage
protocol.Message
}
One stored message with when it was added, who produced it and what it cost
func UnmarshalEntry ¶
Rebuilds one entry written by MarshalEntry
type Header ¶
type Header struct {
ID string `json:"id"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Title string `json:"title,omitempty"`
Named bool `json:"named,omitempty"`
Model string `json:"model,omitempty"`
Parent string `json:"parent,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Usage protocol.Usage `json:"usage"`
Last protocol.Usage `json:"last"`
Messages int `json:"messages"`
Records int `json:"records"`
}
Metadata and usage of a session as stored
type Info ¶
type Info struct {
ID string `json:"id"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Title string `json:"title,omitempty"`
Model string `json:"model,omitempty"`
Parent string `json:"parent,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Messages int `json:"messages"`
Records int `json:"records"`
Usage protocol.Usage `json:"usage"`
// Whether another process has the session open right now
Busy bool `json:"busy,omitempty"`
// Why a store could not read the session, empty when it loaded cleanly
Error string `json:"error,omitempty"`
}
Metadata of a session without its messages
type MarkdownOptions ¶
type MarkdownOptions struct {
// Adds the time and producing agent under each heading
Timestamps bool
// Appends the record log after the transcript
Records bool
}
Controls which parts of a transcript the Markdown export includes
type Record ¶
Event worth replaying on the timeline that is not a message, such as an approval or a compaction
func UnmarshalRecord ¶
Rebuilds one record written by MarshalRecord
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Ordered messages of a conversation and the token usage its responses have cost so far
func FromHeader ¶
Session rebuilt from a header, its entries and its records
func (*Session) AddResponse ¶
Appends the assistant turn of a response produced by agent and adds its usage to the totals
func (*Session) AddResults ¶
func (s *Session) AddResults(agent string, results []protocol.ToolResult) Entry
Appends one tool message carrying every result of a tool round run by agent
func (*Session) Compact ¶
Replaces everything before the last keep messages with a summary ahead of a user turn and resets Last
func (*Session) Fork ¶
Starts a new session carrying a copy of the transcript, usage reset and parent recorded
func (*Session) Last ¶
Usage of the most recent response, whose input side measures the current context
func (*Session) MarkdownWith ¶
func (s *Session) MarkdownWith(o MarkdownOptions) string
Renders the transcript as Markdown honoring the options
func (*Session) Project ¶
Project root the session was started under, empty for one started before projects were recorded
func (*Session) Prune ¶
Remembers the stub that stands in for the tool result in requests from now on
func (*Session) Pruned ¶
Stub standing in for the tool result, false while the result still goes out whole
func (*Session) Rename ¶
Names the session as a person chose, an empty name handing the title back to derivation
func (*Session) Snapshot ¶
Copies the messages so callers can build a request without holding the lock
type Store ¶
type Store struct {
Dir string
// contains filtered or unexported fields
}
Store appending one JSON line per message to a log per session under a directory, so a crash loses at most the last line
Several processes may share the directory. Each write and read holds the lock of the session for its duration, and a process that works on a session holds its lease for as long as it has the session open, so another process sees the session as busy rather than silently writing a diverging copy of it
func (*Store) Lease ¶
Takes the lease of a session for this process, a no-op when it already holds it and ErrBusy when another process does
func (*Store) List ¶
Lists stored sessions newest first from the last complete header line of each log, marking those another process has open
func (*Store) ListProject ¶
Lists the sessions that belong to a project, by the label stores and apps set at creation
func (*Store) Load ¶
Replays the log, the latest header winning, ignoring an unterminated final line without touching the file